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

          主站蜘蛛池模板: 黎川县| 黔江区| 钦州市| 贡觉县| 巴塘县| 安图县| 马尔康县| 江城| 河北区| 鄂尔多斯市| 长治县| 启东市| 乐清市| 潼南县| 老河口市| 陆河县| 凤凰县| 新巴尔虎左旗| 郓城县| 大石桥市| 伊春市| 威海市| 巨鹿县| 潞城市| 怀化市| 浑源县| 日土县| 中方县| 兰考县| 白朗县| 游戏| 东至县| 毕节市| 子长县| 绥宁县| 丘北县| 武邑县| 靖江市| 莆田市| 上杭县| 博爱县|