jQuery實(shí)現(xiàn)列表的增加和刪除功能
具體代碼如下所示:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery</title> <style> </style> </head> <body> <div> <table style="margin: 10px auto;" id="tableList"> <thead> <tr> <th>name</th> <th>price</th> <th>delete</th> </tr> </thead> <tbody> <tr> <td>a</td> <td>123</td> <td><a href="#" rel="external nofollow" rel="external nofollow" >delete</a></td> </tr> <tr> <td>c</td> <td>3453</td> <td><a href="#" rel="external nofollow" rel="external nofollow" >delete</a></td> </tr> </tbody> </table> </div> <form> <table style="margin:0 auto;"> <tr> <td>name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>price</td> <td><input type="text" name="price"></td> </tr> <tr> <td colspan="2"> <input type="submit" value="submit" id="add"> </td> </tr> </table> </form> <script src="../js/vendor/jquery-3.2.1.min.js"></script> <script> var $tableList=$("#tableList"); //tianjia $("#add").click(function(){ var tdName= $("input[name=name]").val(); var tdPrice = $("input[name=price]").val(); $("<tr></tr>").append("<td>"+tdName+"</td>") .append("<td>"+tdPrice+"</td>") .append("<td><a href='#?'>delete</a></td>") .appendTo($("#tableList>tbody")) .find("a").click(function(){ $(this).parent().parent().remove(); }); $("input[name=name]").val(""); $("input[name=price]").val(""); return false; }) //delete $("#tableList>tbody a").click(function(){ $(this).parent().parent().remove(); }) </script> </body> </html>
總結(jié)
以上所述是小編給大家介紹的jQuery實(shí)現(xiàn)列表的增加和刪除功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- 基于jquery實(shí)現(xiàn)多選下拉列表
- jQuery+Ajax請求本地?cái)?shù)據(jù)加載商品列表頁并跳轉(zhuǎn)詳情頁的實(shí)現(xiàn)方法
- jQuery插件select2利用ajax高效查詢大數(shù)據(jù)列表(可搜索、可分頁)
- jQuery實(shí)現(xiàn)Select下拉列表進(jìn)行狀態(tài)選擇功能
- jQuery實(shí)現(xiàn)聯(lián)動下拉列表查詢框
- jquery實(shí)現(xiàn)圖片列表鼠標(biāo)移入微動
- JQuery實(shí)現(xiàn)列表中復(fù)選框全選反選功能封裝(推薦)
- 基于jQuery和Bootstrap框架實(shí)現(xiàn)仿知乎前端動態(tài)列表效果
- 利用jQuery對無序列表排序的簡單方法
- 多功能jQuery樹插件zTree實(shí)現(xiàn)權(quán)限列表簡單實(shí)例
- jQuery EasyUI學(xué)習(xí)教程之datagrid點(diǎn)擊列表頭排序
相關(guān)文章
自定義jquery模態(tài)窗口插件無法在頂層窗口顯示問題
自定義一個(gè)jquery模態(tài)窗口插件只能在mainFrame窗口中顯示,無法在頂層窗口顯示2014-05-05jQuery實(shí)現(xiàn)下拉加載功能實(shí)例代碼
本文通過一段實(shí)例代碼給大家介紹jquery實(shí)現(xiàn)下拉加載功能,代碼簡單易懂,需要的朋友參考下吧2016-04-04jQuery Dialog 打開時(shí)自動聚焦的解決方法(兩種方法)
這篇文章主要介紹了jQuery Dialog 打開時(shí)自動聚焦的解決方法,及jquery dialog打開時(shí),自動聚焦在第一個(gè)控件上的方法,對jquery dialog相關(guān)知識感興趣的朋友通過本文一起學(xué)習(xí)吧2016-11-11淺談jQuery頁面的滾動位置scrollTop、scrollLeft
官方文檔的解釋有點(diǎn)含糊,其實(shí)換個(gè)角度就很容易理解了,scrollTop獲取的是內(nèi)部元素超出外部容器的高度。 例如:$('window').scrollTop()獲取的就是當(dāng)前這個(gè)頁面超出窗口最上端的高度,scrollLeft與此同理2015-05-05jQuery Ajax向服務(wù)端傳遞數(shù)組參數(shù)值的實(shí)例代碼
在使用MVC時(shí),向服務(wù)器端發(fā)送POST請求時(shí)有時(shí)需要傳遞數(shù)組作為參數(shù)值,下面通過實(shí)例代碼給大家介紹jQuery Ajax向服務(wù)端傳遞數(shù)組參數(shù)值的方法,一起看看吧2017-09-09解決Jquery鼠標(biāo)經(jīng)過不?;瑒拥膯栴}
在鼠標(biāo)經(jīng)過的時(shí)候不停的顯示隱藏html元素,正確的寫法應(yīng)該是下面這樣的,需要的朋友可以參考下2014-03-03利用jquery正則表達(dá)式在頁面驗(yàn)證url網(wǎng)址輸入是否正確
這篇文章主要介紹了關(guān)于利用jquery正則表達(dá)式在頁面驗(yàn)證url網(wǎng)址輸入是否正確的相關(guān)資料,文中給出了完整的示例代碼,對大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-04-04讀jQuery之七 判斷點(diǎn)擊了鼠標(biāo)哪個(gè)鍵的代碼
jQuery中的which即可以是鍵盤的鍵值,也可以是鼠標(biāo)的鍵值。2011-06-06