jQuery實(shí)現(xiàn)表格的增、刪、改操作示例
本文實(shí)例講述了jQuery實(shí)現(xiàn)表格的增、刪、改操作。分享給大家供大家參考,具體如下:
這里實(shí)現(xiàn)的是在jQuery中通過(guò)按鈕的形式,對(duì)表格進(jìn)行的一些基本操作,可以實(shí)現(xiàn)表格的增刪改操作,并實(shí)現(xiàn)對(duì)鼠標(biāo)事件監(jiān)聽(tīng),實(shí)現(xiàn)表格的高亮行操作。
<head> <meta charset="UTF-8"> <title>www.dbjr.com.cn jQuery表格操作</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { //添加一行 $("#one").click(function() { var $td = $("#trOne").clone(); $("table").append($td); $("table tr:last").find("input").val(""); }); //刪除一行 $("#two").click(function() { $("table tr:not(:first):last").remove(); }); //刪除所有行 $("#three").click(function() { /*var len=$("tr").length; for(var i=0;i<=len;i++){ $("tr")[i].remove(); }*/ //除第一行為其它行刪除 $("tr:not(:first)").remove(); }); //刪除選中的行 $("#four").click(function() { //遍歷選中的checkbox $("[type='checkbox']:checked").each(function() { //獲取checkbox所在行的順序 n = $(this).parents("tr").index(); $("table").find("tr:eq(" + n + ")").remove(); }); }); //設(shè)置高亮行 $("tr").mouseover(function() { $(this).css("background-color","red"); }); $("tr").mouseout(function(){ $(this).css("background-color","white"); }); }); </script> </head> <body> <input type="button" id="one" value="添加一行" /><br /> <input type="button" id="two" value="刪除一行" /><br /> <input type="button" id="three" value="刪除所有行" /><br /> <input type="button" id="four" value="刪除選中的行" /><br /> <table width="400px" height="50px" border="2px" cellspacing="0" cellpadding="0"> <tr id="trOne"> <td><input type="checkbox" name=""></td> <td><input type="" name="" value="姓名" </td> <td><input type="" name="" value="年齡" </td> <td><input type="" name="" value="性別" </td> </tr> <tr> <td><input type="checkbox" name=""></td> <td><input type="" name="" value="張三" </td> <td><input type="" name="" value="18" </td> <td><input type="" name="" value="男" </td> </tr> <tr> <td><input type="checkbox" name=""></td> <td><input type="" name="" value="李四" </td> <td><input type="" name="" value="18" </td> <td><input type="" name="" value="男" </td> </tr> <tr> <td><input type="checkbox" name=""></td> <td><input type="" name="" value="王五" </td> <td><input type="" name="" value="18" </td> <td><input type="" name="" value="男" </td> </tr> </table> </body>
效果圖如下:
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《jQuery表格(table)操作技巧匯總》、《jQuery操作xml技巧總結(jié)》、《jQuery form操作技巧匯總》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery動(dòng)態(tài)操作表單示例【基于table表格】
- jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能【推薦】
- 基于jquery的實(shí)現(xiàn)簡(jiǎn)單的表格中增加或刪除下一行
- jQuery實(shí)現(xiàn)表格行和列的動(dòng)態(tài)添加與刪除方法【測(cè)試可用】
- jQuery對(duì)table表格進(jìn)行增刪改查
- 基于jQuery的動(dòng)態(tài)增刪改查表格信息,可左鍵/右鍵提示(原創(chuàng)自Zjmainstay)
- jquery動(dòng)態(tài)增加刪除表格行的小例子
- 基于jQuery實(shí)現(xiàn)表格的查看修改刪除
- JQuery動(dòng)態(tài)添加和刪除表格行的方法
- 原生JS和JQuery動(dòng)態(tài)添加、刪除表格行的方法
- jquery動(dòng)態(tài)增加刪減表格行特效
相關(guān)文章
jQuery避免$符和其他JS庫(kù)沖突的方法對(duì)比
jQuery中需要用到$符號(hào),如果其他js庫(kù)也定義了$符號(hào),那么就會(huì)造成沖突,會(huì)影響到j(luò)s代碼的正常執(zhí)行,下面有幾個(gè)不錯(cuò)的解決方法,大家可以參考下2014-02-02jQuery電話(huà)號(hào)碼驗(yàn)證實(shí)例
這篇文章主要為大家詳細(xì)介紹了jQuery電話(huà)號(hào)碼驗(yàn)證實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01jquery imgareaselect 使用利用js與程序結(jié)合實(shí)現(xiàn)圖片剪切
當(dāng)前在ff3下,用jquery的 width()與height()函數(shù),在不設(shè)置圖片的寬度與高度的時(shí)候,不能取到 需要在圖片load函數(shù)里面初始化才可以2009-07-07jquery自動(dòng)填充勾選框即把勾選框打上true
jquery自動(dòng)填充勾選框,即把勾選框打上(true),然后通過(guò)ajax方式獲得勾選項(xiàng)列表,再把列表內(nèi)的選項(xiàng)打上2014-03-03jquery打開(kāi)直接跳到網(wǎng)頁(yè)最下面、最低端實(shí)現(xiàn)代碼
接下來(lái)為大家詳細(xì)介紹下jquery如何實(shí)現(xiàn)打開(kāi)直接跳到網(wǎng)頁(yè)最下面,最低端,感興趣的朋友可以參考下哈2013-04-04jQuery中使用Ajax獲取JSON格式數(shù)據(jù)示例代碼
有時(shí)候我們需要讀取JSON格式的數(shù)據(jù)文件,在jQuery中可以使用Ajax或者 $.getJSON()方法實(shí)現(xiàn),下面有個(gè)不錯(cuò)的示例,需要的朋友可以參考下2013-11-11