国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

jQuery實現表格的增、刪、改操作示例

2024-05-06 15:42:53
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery實現表格的增、刪、改操作。分享給大家供大家參考,具體如下:

這里實現的是在jQuery中通過按鈕的形式,對表格進行的一些基本操作,可以實現表格的增刪改操作,并實現對鼠標事件監聽,實現表格的高亮行操作。

<head>  <meta charset="UTF-8">  <title>www.survivalescaperooms.com 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();        });      });      //設置高亮行      $("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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 迭部县| 南和县| 七台河市| 扶余县| 城口县| 汉源县| 大安市| 梁山县| 襄汾县| 尼玛县| 迁安市| 玉田县| 陇西县| 井陉县| 图木舒克市| 英德市| 突泉县| 塘沽区| 万州区| 蛟河市| 抚州市| 册亨县| 洪洞县| 洞头县| 随州市| 乐都县| 收藏| 博客| 水城县| 隆昌县| 罗田县| 东辽县| 绥江县| 兰溪市| 谢通门县| 天等县| 长乐市| 古蔺县| 蓬溪县| 九寨沟县| 南宁市|