Tang Anping

          Love Java

          JavaScript文本和文件節點操作

          這幾天的調試,總結了一些JavaScript的經驗,如果大家有更好的方法,歡迎交流!
          本人喜歡以代碼的方式交流,不很喜歡紙上談兵。
          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">
          ????????
          //?禁止文件上傳文本框輸入文字,然后彈出消息提醒,用得到元素節點,然后清空的方法不行,可以用下面的函數得到需要的效果
          ????????function?toolTip()?{
          ????????????
          //?得到<span>跨字符節點
          ????????????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

          主站蜘蛛池模板: 镇原县| 贡嘎县| 长泰县| 沐川县| 哈尔滨市| 亚东县| 高陵县| 雅江县| 阳春市| 长沙市| 呼伦贝尔市| 孟津县| 双鸭山市| 太谷县| 丹棱县| 缙云县| 甘泉县| 嵊州市| 普安县| 大丰市| 炉霍县| 新源县| 鹰潭市| 习水县| 额敏县| 朝阳县| 永春县| 来凤县| 黔江区| 黄平县| 小金县| 汕头市| 纳雍县| 察雅县| 贵港市| 无棣县| 乌拉特前旗| 泗洪县| 观塘区| 呈贡县| 三明市|