posts - 22, comments - 17, trackbacks - 0, articles - 15
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          怎樣動態添加文本框并處理

          Posted on 2007-01-04 14:44 碼農cz 閱讀(1435) 評論(1)  編輯  收藏 所屬分類: As u

          我在做項目時曾碰到這個問題,怎樣動態地添加一個文本框或文件域,這在網上很容易找到。但對怎樣處理提交的動態數據就很少有這方面的信息了。本人翻閱了一些資料,把自己的方法寫了下來,以饗讀者。

          1.提交表單

          ?

          <html>
          <body>
          ?<form?name
          = " form " ?method = " post " ?action = " add.jsp " >
          ???<input?name
          = " button " ?type = button?onClick = 'additem( " tb " )'?value = " 添加>> " >
          ?<table?id
          = " tb " >
          ?</table>
          <script?language
          = " javascript " >

          function?additem(id)
          {
          ??var?row
          , cell , str ;
          ??row? = ?eval( " document.all[ " +' " '+id+' " '+ " ] " ).insertRow() ;
          ??if(row?! = ?null?)
          ?????{
          ????????cell?
          = ?row.insertCell() ;
          ????????str = " <input?type= " +' " '+ " text " +' " '+ " ?name= " +' " '+ " StuName " +' " '+ " ><input?type= " +' " '+ " button " +' " '+ " ?value= " +' " '+ " 刪除 " +' " '+ " ?onclick='deleteitem(this, " +' " '+ " tb " +' " '+ " );'> "
          ???cell.innerHTML
          = str ;

          ??????}
          }
          function?deleteitem(obj
          , id)
          {
          ??var?rowNum
          , curRow ;
          ??curRow? = ?obj.parentNode.parentNode ;
          ??rowNum? = ?eval( " document.all. " +id).rows.length?-? 1 ;
          ??eval( " document.all[ " +' " '+id+' " '+ " ] " ).deleteRow(curRow.rowIndex) ;
          }
          </script>
          ???<p>
          ?????<input?type
          = " submit " ?name = " submit " ?value = " 提交 " >
          ???</p>
          ?</form>
          </body>
          </html>

          ?

          2.處理數據

          < body >
          < table? border ="1" >< tr >< td? colspan ="2" > eg </ td ></ tr >
          <%
          Enumeration?params
          = request.getParameterNames();
          while (params.hasMoreElements()){
          String ?name = ( String )params.nextElement();
          String []?values = request.getParameterValues(name);
          if (name.equals( " StuName " )){
          %>
          < tr >
          < td > <% = name %> </ td >
          < td >
          <%
          for ( int ?index = 0 ;index < values.length;index ++ ){
          %>
          <% = values[index] %>
          <% }} %>
          </ td >
          </ tr >
          </ table >
          </ body >


          評論

          # re: 怎樣動態添加文本框并處理  回復  更多評論   

          2007-10-26 14:46 by 123
          good ,thx!
          主站蜘蛛池模板: 改则县| 洛川县| 油尖旺区| 寿宁县| 富阳市| 湟中县| 贵定县| 景东| 宜良县| 祁连县| 和林格尔县| 呼图壁县| 鄂尔多斯市| 武陟县| 梁平县| 探索| 皋兰县| 道真| 西宁市| 丹凤县| 青神县| 澄迈县| 织金县| 济南市| 张家港市| 阿坝| 兴义市| 娄烦县| 梧州市| 樟树市| 兰州市| 绍兴市| 梁河县| 龙江县| 吉首市| 安宁市| 红河县| 平泉县| 霍林郭勒市| 栾川县| 峨眉山市|