首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

全选按钮无法达到全选要求,这是咋回事

2012-08-09 
全选按钮无法达到全选要求,这是怎么回事产品表格是通过JSON返回的数据按照如下设计好的模板生成。var proTa

全选按钮无法达到全选要求,这是怎么回事
产品表格是通过JSON返回的数据按照如下设计好的模板生成。
var proTable = "";
  proTable = proTable + "<table width=100% border=0 cellpadding=0 cellspacing=0>";
  proTable = proTable + "<form action='/Users/AddProHouse'method='post'><tr><td height=25 rowspan=2 align=center class=border_bottom><input name=all id=all type=checkbox />全选</td>";
  proTable = proTable + "<td height=25 rowspan=2 align=center class=border_bottom>产品名称</td>";
  proTable = proTable + "<td height=25 rowspan=2 align=center class=border_bottom>产品代号</td>";
  proTable = proTable + "<td height=25 rowspan=2 align=center class=border_bottom>品种</td>";
  proTable = proTable + "<td height=25 rowspan=2 align=center class=border_bottom>品牌</td>";
  proTable = proTable + "<td height=25 colspan=3 align=center class='border_bottom border_left'>品质/价格</td>";
  proTable = proTable + "</tr>";
  proTable = proTable + "<tr>";
  proTable = proTable + "<td height=25 align=center class='border_bottom border_left'>原厂</td>";
  proTable = proTable + "<td height=25 align=center class='border_bottom'>配套</td>";
  proTable = proTable + "<td height=25 align=center class='border_bottom'>副厂</td>";
  proTable = proTable + "</tr>";
  var i;
  for (i = 0; i < data.length - 1; i++) {
  proTable = proTable + "<tr>"
  proTable = proTable + "<td align=center class=border_bottom>><input name=p_list id=p_list type=checkbox value='" + $.trim(data[i].cpxh) + "'/></td>";
  proTable = proTable + "<td align=center class=border_bottom>" +$.trim(data[i].cpxh)+ $.trim(data[i].cpmc) + "</td>";
  proTable = proTable + "<td align=center class=border_bottom>" + $.trim(data[i].cpdh) + "</td>";
  proTable = proTable + "<td align=center class=border_bottom>" + $.trim(data[i].pzmc) + "</td>";
  proTable = proTable + "<td align=center class=border_bottom>" + $.trim(data[i].ppmc) + "</td>";
  proTable = proTable + "<td align=center class='border_bottom border_left'>" + $.trim(data[i].ycxj) + "</td>";
  proTable = proTable + "<td align=center class=border_bottom>" + $.trim(data[i].ptxj) + "</td>";
  proTable = proTable + "<td align=center class=border_bottom>" + $.trim(data[i].fcxj) + "</td>";
  proTable = proTable + "</tr>";
  }
  proTable = proTable + "</form></table>";
  $("#ProListTable").html(proTable)
点击全选代码
  $(function () {
  $("#all").click(function () {
  $("input[name='p_list']").attr("checked", $(this).attr("checked"));
  });
  $("#gwAddbtn").click(function () {
  var p_lists = $("input[id=p_list]:checked");


  var arr = new Array();
  p_lists.each(function (key, value) {
  arr[key] = $(value).val();
  })
  if (p_lists.length < 1) {
  alert("你还未选择产品,请选择后添加");
  return false;
  }
  });
  });


怎么无法全部一次选择

[解决办法]
id值页面上必须唯一
检查$(this).attr("checked")的结果是否正确,不同的版本这个语法已经失效
[解决办法]
$("#all").click(function () {
$(":checkbox").attr("checked","true"));
});
[解决办法]
如果没有其他的checkbox 就用这个绝招吧

JScript code
$("#all").click(function () {  $(":checkbox").attr("checked","true"));  }); 

热点排行