日期:2014-05-16  浏览次数:20389 次

datatable在每一行的第一列塞一个checkbox怎么搞
datatable在每一行的第一列塞一个checkbox怎么搞

$("#tabs-2 tbody tr").each(function(){
  var posX = $(this).find("td:first").position().left;
  var posY = $(this).find("td:first").position().top;
  var box="<input type=\"checkbox\" name=\"checkEmp\"></input>"; $("#isSelect").html(box).css({display:'block',left:posX,top:posY}).appendTo($(this).find("td:first"));
});

我这样写有什么问题呢

------解决方案--------------------
你好,不知到你的表格的第一列是否有值,如果有值你可以试试这样做
$(document).ready(function(key, value){
$("#tabs-2 tbody tr").each(function(){
var posX = $(this).find("td:first").position().left;
var posY = $(this).find("td:first").position().top;
var box="<input type=\"checkbox\" name=\"checkEmp\"></input>";  
$("<span> </span>").html(box).css({left:posX,top:posY}).appendTo($(this).find("td:first"));
});
如果你的第一列没有值,可以直接这样使用:
$(document).ready(function(key, value){
$("#tabs-2 tbody tr").each(function(){
var posX = $(this).find("td:first").position().left;
var posY = $(this).find("td:first").position().top;
var box="<input type=\"checkbox\" name=\"checkEmp\"></input>";  
$(this).find("td:first").html(box);
});
 不知对你是否有帮助。