单击按钮禁用复选框

Onclick button disables checkboxes

本文关键字:复选框 按钮 单击      更新时间:2023-09-26

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

。。。
<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;"/>

并且添加点击功能的按钮已经有很多点击功能。

<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);
  });
});
你可以

这样做:

    $(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");
    });
});