$(document).ready(function(){
for(i=0;i<100;i++){
$("#checkName"+i).click(function(){
    if($("#checkName"+i).attr("checked")==undefined){
    $("#checkName"+i).attr("value",0)
    //alert($("#checkName0").attr("value"));
    
}
else{
$("#checkName"+i).attr("value",1)
//alert($("#checkName0").attr("value"));

}
});
};
});
求改

解决方案 »

  1.   

    $(document).ready(function() {
        for (i = 0; i < 100; i++) {
    (function(i){
    $("#checkName" + i).click(function() {
    if ($("#checkName" + i).attr("checked") == undefined) {
    $("#checkName" + i).attr("value", 0)
    }
    else {
    $("#checkName" + i).attr("value", 1)
    } });
    })(i);
        };});
    试试
      

  2.   


    $(document).ready(function(){
    for(i=0;i<100;i++){
     $("#checkName"+i).click(function(){
     $(this).val()=$(this).attr("checked")?1:0;
     });
     };
     });
      

  3.   

    <tr>
    <td>
    <label>
    <input name="login.purshase" type="checkbox" id="checkName0"
    value="" <s:if test="#session.purshaseGetId==1">checked</s:if> />

    <!--<input name="purshase" type="checkbox" id="checkName0" <s:if test="值==1">checked</s:if> >-->
    </label>
    </td>

    <td>
    采购管理
    </td>
    </tr>
    <tr>
    <td>
    <label>
    <input name="login.sell" type="checkbox" id="checkName1"
    value=""
    <s:if test="#session.sellGetId==1">checked</s:if> />
    </label>
    </td>
    <td>
    销售管理
    </td>
    </tr>
      

  4.   


    $(document).ready(function(){
    for(i=0;i<100;i++){
     $("#checkName"+i).click(function(){
     $(this).val($(this).attr("checked")?1:0);
     });
     };
     });
      

  5.   


    $(document).ready(function(){
    $('input[id^=checkName]').each(function() {
    if($(this).attr('checked')) {
    $(this).val(1);
    } else {
    $(this).val(0);
    }
    });
    });
      

  6.   

    8楼的 有效果  他值更新了id为checkName0的值 checkName1 checkName2包括后面的 全都没变。。
      

  7.   

    8楼你的 不是更新了checkName0的值  而且 更新出来的全为0  选了 还是为0
      

  8.   

     数据库读出来的 1的话默认就选择了 0反之 然后所有的checkbox进行value修改啊 选择为1  不选择为0
      

  9.   


    $(document).ready(function(){
    for(i=0;i<100;i++){
     var that=$("#checkName"+i);
     that.val(that.attr("checked")?1:0);
     that.click(function(){
     $(this).val($(this).attr("checked")?1:0);
     });
     };
     });
      

  10.   

    你直接把值写在value里不就行,还重新判断赋值多累啊。
      

  11.   

    可以修改 只能0修改1  但是选中的 修改不了 是Null
      

  12.   


    一开始 你不需要赋值了 我上面Struts标签已经赋值好了  只需要修改 就是告诉你下 一开始 有的有值而已
      

  13.   


    $(document).ready(function(){
    $('input[id^=checkName]').each(function() {
    var cb = $(this);
    cb.val(cb.attr('checked') ? 1 : 0);
    cb.click(function() {
    cb.val(cb.attr('checked') ? 1 : 0);
    });
    });
    });那需要注册点击事件
      

  14.   

    你判断有没有值在哪判断?后台?后台的话,没选中的选项不会提交到后台去,一定是NULL
      

  15.   

    对了 22 楼你不是说过能在VALUE里面能直接判断么 怎么判断 如果会STRUTS标签最好了
      

  16.   

    <tr>
    <td>
    <label>
    <input name="login.purshase" type="checkbox" id="checkName0"
    value="" <s:if test="#session.purshaseGetId==1">checked</s:if> />

    <!--<input name="purshase" type="checkbox" id="checkName0" <s:if test="值==1">checked</s:if> >-->
    </label>
    </td>

    <td>
    采购管理
    </td>
    </tr>
    <tr>
    <td>
    <label>
    <input name="login.sell" type="checkbox" id="checkName1"
    value=""
    <s:if test="#session.sellGetId==1">checked</s:if> />
    </label>
    </td>
    <td>
    销售管理
    </td>
    </tr>
    <tr>
    <td>
    <label>
    <input name="login.client" type="checkbox" id="checkName2"
    value=""
    <s:if test='#session.clientGetId==1'>checked</s:if> />
    </label>
    </td>
    <td>
    客户管理
    </td>
    </tr>
      

  17.   

    修改他的checkbox的值啊 不选就是默认的值