Onclick按钮禁用复选框

时间:2013-09-27 05:02:03

标签: javascript jquery html

。 。我找不到按钮上的onclick功能的正确答案,禁用三个复选框。 。

<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>
<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>
<input id="option" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>

添加onclick功能的按钮已经有很多onclick功能。

<input type="button" class="button2" id="item2" value="Add to Cart" Title="Add to Cart" onClick="addItem_check('item_listing_100','ItemTable','100','Amul Butter','500','g','150.00','1','kg','200.00','2','kg','250.00'); amul1.style.backgroundColor='#c2ed5c'; if(this.value=='Add to Cart') {this.value = 'Remove from Cart'}; item2();"/>

所以请给我一个解决方案的人

4 个答案:

答案 0 :(得分:1)

您尝试执行的操作的问题是,对于所有三个复选框,您具有相同的id="option"。它们必须是独一无二的。

您可以执行以下操作:

<input id="option1" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>
<input id="option2" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>
<input id="option3" name="item_number" type="checkbox" class="ckbox" value="1" onclick="this.checked=!this.checked;"/>

在Javascript中:

$(function(){
  $('#button1').click(function(){
       for(var i=1;i<=3;i++)
           $('#option'+i).prop('disabled', true);
  });
});

答案 1 :(得分:0)

你可以这样做:

    $(function(){
        $('#button1').click(function(){
        $('input[type=checkbox]').attr('disabled','true');
        });
   });

答案 2 :(得分:0)

试试这个,

 $(function(){
        $('#button1').click(function(){
        $('.ckbox').prop('disabled','true');
        });
   });

答案 3 :(得分:0)

尝试通过单击按钮禁用复选框。

'item2'是按钮&amp;的id根据您的示例,'ckbox'是复选框类。

jQuery(function($) {
    $("#item2").click(function(){
        $(".ckbox").attr("disabled","disabled");
    });
});
相关问题