关于 table 的一些js操作

来源:互联网 发布:网络交易管理办法2017 编辑:程序博客网 时间:2024/05/16 18:47

jQuery实现表格选中行变色,单选选中

   $("tbody tr").click(function() {    $(this).addClass("s1").siblings().removeClass("s1");    $(this).find(":radio").attr("checked", true);   });

全选或全不选 此传入的参数为this

function checkAll(evt)  {      $("#table1 tr").find("input[ type = 'checkbox' ]").each(function(i){          $(this).attr("checked",evt.checked)      });   } function checkAll(evt)  {      $("#table1 tr").find("input[ type = 'checkbox' ]").attr("checked",evt.checked);  }  

获取每一行指定的单元格的值

var  arr  = [];  $("#table1 tr td:nth-child(1)").each(function (key, value) {      arr.push($(this).html());  });  var  result  =  arr .join(',');  

得到(设置)某个单元格的值

//设置table1,第2个tr的第一个td的值。   $("#table1 tr:eq(1) td:nth-child(1)").html("value");   //获取table1,第2个tr的第一个td的值。   $("#table1 tr:eq(1) td:nth-child(1)").html();  
原创粉丝点击