Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Onclick按钮禁用复选框_Javascript_Jquery_Html - Fatal编程技术网

Javascript Onclick按钮禁用复选框

Javascript Onclick按钮禁用复选框,javascript,jquery,html,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="th

。我找不到一个按钮上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();"/>


因此,请给我一个解决方案,伙计们。您试图做的问题是,这三个复选框都有相同的
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')。单击(函数(){
对于(var i=1;i你可以这样做:

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

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

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

根据您的示例,“item2”是按钮的id,“ckbox”是复选框的类别

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

id必须是唯一的..函数
addItem\u check
item2
有什么作用?Rohan addItem\u check将项目添加到购物车,而item2我正在使用复选框禁用函数..到目前为止还不太好
onclick=“this.checked=!this.checked;”“
有什么帮助吗?必须使用prop()而不是attr()您必须使用prop()而不是attr()@RohanKumar:谢谢。