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

首頁 > 語言 > JavaScript > 正文

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

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

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

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

<head>  <meta charset="UTF-8">  <title>m.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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 阳信县| 土默特右旗| 黄大仙区| 密山市| 宝坻区| 台东县| 永州市| 耒阳市| 安塞县| 宁海县| 乌什县| 龙海市| 安多县| 保靖县| 施秉县| 咸宁市| 兰州市| 阜城县| 聊城市| 云和县| 丹巴县| 镇远县| 商都县| 龙海市| 石楼县| 金山区| 乌拉特前旗| 安国市| 昌平区| 沙坪坝区| 牙克石市| 望江县| 安龙县| 万源市| 津南区| 凉山| 从江县| 观塘区| 天柱县| 海原县| 大庆市|