Tang Anping

          Love Java

          JavaScript文本和文件節(jié)點(diǎn)操作

          這幾天的調(diào)試,總結(jié)了一些JavaScript的經(jīng)驗(yàn),如果大家有更好的方法,歡迎交流!
          本人喜歡以代碼的方式交流,不很喜歡紙上談兵。
          elementOper.jsp
          <%@?page?language="java"?import="java.util.*"?pageEncoding="GB2312"%>
          <%
          String?path?
          =?request.getContextPath();
          String?basePath?
          =?request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
          <html>
          ??
          <head>
          ????
          <base?href="<%=basePath%>">
          ????
          ????
          <title>ElementOper</title>
          ????
          ????
          <meta?http-equiv="pragma"?content="no-cache">
          ????
          <meta?http-equiv="cache-control"?content="no-cache">
          ????
          <meta?http-equiv="expires"?content="0">????
          ????
          <meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3">
          ????
          <meta?http-equiv="description"?content="This?is?my?page">
          ????
          <script?type="text/javascript">
          ????????
          //?禁止文件上傳文本框輸入文字,然后彈出消息提醒,用得到元素節(jié)點(diǎn),然后清空的方法不行,可以用下面的函數(shù)得到需要的效果
          ????????function?toolTip()?{
          ????????????
          //?得到<span>跨字符節(jié)點(diǎn)
          ????????????var?fileSpan?=?document.getElementById("fileSpan");
          ????????????
          //?重新給<span>賦值
          ????????????fileSpan.innerHTML?=?'<input?name="fileUpload"?title="請(qǐng)點(diǎn)擊瀏覽"??type="file"?value="aaaa"?onkeyup="toolTip()">';
          ????????????
          //?彈出提醒信息
          ????????????alert("請(qǐng)點(diǎn)擊后面的瀏覽,選擇需要上傳的文件!");
          ????????}

          ????????
          //?初始化文本
          ????????function?initialValue()?{
          ????????????var?txt?
          =?document.getElementById("username");
          ????????????
          //?設(shè)置字體顏色
          ????????????txt.style.color?=?"gray";
          ????????????
          //?給元素賦值
          ????????????txt.value?=?"--請(qǐng)?jiān)谶@里輸入姓名--";
          ????????}

          ????????
          //?清空文本
          ????????function?clearText()?{
          ????????????var?txt?
          =?document.getElementById("username");
          ????????????txt.value?
          =?"";
          ????????????txt.style.color?
          =?"black";
          ????????}

          ????
          </script>
          ??
          </head>
          ??
          ??
          <body?onload="initialValue()">
          ????
          <form?action=""?name="fileForm"?enctype="multipart/form-data">
          ????????
          <span?id="fileSpan"><input?name="fileUpload"?title="請(qǐng)點(diǎn)擊瀏覽"??type="file"?value="aaaa"?onkeydown="toolTip()"></span>
          ????
          ????????
          <table?style="background-color:?#D4E1EE;border-bottom-color:?#cccccc"?cellpadding="1"??cellspacing="0"?border="0">
          ????????????
          <tr>
          ????????????????
          <td?style="border-color:?gray;">
          ????????????????????
          <input?type="text"?style="border:?0;border-color:?gray;"?name="username"?onfocus="clearText()">
          ????????????????
          </td>
          ????????????
          </tr>
          ????????
          </table>
          ????
          </form>
          ??
          </body>
          </html>

          posted on 2006-12-05 09:10 Tang Anping 閱讀(1012) 評(píng)論(0)  編輯  收藏 所屬分類: JavaScript


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 沈丘县| 都昌县| 大连市| 玉山县| 永昌县| 龙陵县| 淮南市| 浦江县| 霍林郭勒市| 许昌县| 依兰县| 紫金县| 乐昌市| 应城市| 吉林省| 大新县| 晋江市| 大石桥市| 保定市| 柯坪县| 远安县| 昌吉市| 海淀区| 榕江县| 革吉县| 沁水县| 阳西县| 玉林市| 玛曲县| 铜山县| 重庆市| 弥渡县| 天等县| 华坪县| 吴川市| 汶上县| 社会| 锦州市| 同江市| 武宁县| 闻喜县|