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 閱讀(1018) 評論(0)  編輯  收藏 所屬分類: JavaScript

          主站蜘蛛池模板: 龙岩市| 东乡县| 肃南| 浦江县| 宁波市| 岐山县| 黄冈市| 静宁县| 临猗县| 满洲里市| 昌都县| 米林县| 宜川县| 榆中县| 永德县| 陆河县| 信丰县| 义乌市| 关岭| 白水县| 芦溪县| 阳高县| 宜宾市| 平阳县| 云安县| 巴林右旗| 永登县| 平遥县| 株洲市| 五家渠市| 米易县| 新宾| 泰兴市| 梅州市| 兴仁县| 泽库县| 阜康市| 新源县| 泸西县| 灵台县| 漾濞|