jquery實現<body>中點擊按鈕後,在<tbody>中顯示一連串文字框

來源:互聯網
上載者:User

標籤:style   blog   color   io   for   ar   cti   div   

HTML中的代碼如下:

 1 <div   style="background:#fff;border-style:solid; border-width:1px 1px 0 1px;border-color:#B8D0D6;"> 2             <div > 3               <div style="margin:-6px 0 0 0"> 4                 <button  class="button gray" type="button"id="addButton">添加座標</button> 5                 <input type="text" name="dwz_rowNum" class="textInput" id="count"  value="1" > 6               </div>  7             </div>             8             <table class="list nowrap "id="table" width="100%"> 9             <thead>10               <tr>11                 <th width="20%"size="18" >ID</th>12                 <th width="20%"size="18" >X軸座標</th>13                 <th width="20%"size="18" >Y軸座標</th>14                 <th width="20%"size="18" >備忘</th>15                 <th width="20%"size="18" >操作</th>16               </tr>17             </thead>18            19             <tbody>20               29             </tbody>30           </table>31         </div>

jquery代碼如下:

 2 jQuery(function($){ 3    //添加行   5     $("#addButton").click(function(){     9       for(var i=1;i<=$("#count")[0].value;i++){10         $("#table>tbody").append(‘<tr><td width="20%"><input name="items.order_id[]" type="text"size="20" value=""></input></td><td width="20%"><input name="items.x_coordinates[]" type="text" value=""></input></td><td width="20%"><inputname="items.y_coordinates[]" type="text" value=""></input></td><td width="20%"><input name="items.remark[]" type="text" value=""></input></td><td width="20%"><button class="btnDel"onclick="deltr(this)">刪除</button></td></tr>‘)11       }12    });13 });14 //刪除行的函數,必須要放domready函數外面15 function deltr(delbtn){    17     $(delbtn).parents("tr").remove();23 };

 

 

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.