Tang Anping

          Love Java

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

          這幾天的調(diào)試,總結(jié)了一些JavaScript的經(jīng)驗,如果大家有更好的方法,歡迎交流!
          本人喜歡以代碼的方式交流,不很喜歡紙上談兵。
          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é)點,然后清空的方法不行,可以用下面的函數(shù)得到需要的效果
          ????????function?toolTip()?{
          ????????????
          //?得到<span>跨字符節(jié)點
          ????????????var?fileSpan?=?document.getElementById("fileSpan");
          ????????????
          //?重新給<span>賦值
          ????????????fileSpan.innerHTML?=?'<input?name="fileUpload"?title="請點擊瀏覽"??type="file"?value="aaaa"?onkeyup="toolTip()">';
          ????????????
          //?彈出提醒信息
          ????????????alert("請點擊后面的瀏覽,選擇需要上傳的文件!");
          ????????}

          ????????
          //?初始化文本
          ????????function?initialValue()?{
          ????????????var?txt?
          =?document.getElementById("username");
          ????????????
          //?設置字體顏色
          ????????????txt.style.color?=?"gray";
          ????????????
          //?給元素賦值
          ????????????txt.value?=?"--請在這里輸入姓名--";
          ????????}

          ????????
          //?清空文本
          ????????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="請點擊瀏覽"??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 閱讀(1011) 評論(0)  編輯  收藏 所屬分類: JavaScript


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 文昌市| 永年县| 东阳市| 抚宁县| 嘉禾县| 涟源市| 安陆市| 措美县| 姚安县| 湘乡市| 南城县| 西乌珠穆沁旗| 新宁县| 突泉县| 黄龙县| 乐陵市| 且末县| 公安县| 元谋县| 修武县| 长顺县| 宁安市| 日照市| 新竹县| 满洲里市| 九龙县| 乃东县| 元江| 石楼县| 桃源县| 项城市| 阆中市| 龙州县| 内黄县| 茶陵县| 宁海县| 建湖县| 米泉市| 增城市| 沈阳市| 收藏|