简体   繁体   English

RemoveAttr 不会删除禁用

[英]RemoveAttr doesn't remove disabled

   <input type="checkbox" name="checking">j'accepte les conditions
   <input type="submit" value="Valider"  id="valide" disabled/>

<script>
    $(document).ready(function(){

         if((input=$("input:checkbox[name=checking]").is(":checked"))){
            $("#valide").prop('disabled',true);
         }

});
    </script>

Hi, i want enable button (valide) when i checked checkbox嗨,当我选中复选框时,我想要启用按钮(valide)

Simply listen for the 'change' event on checkbox and enable/disable the button accordingly.只需侦听复选框上的“更改”事件并相应地启用/禁用按钮。

$("input:checkbox[name=checking]").on('change',function(){
     $("#valide").prop('disabled', !this.checked);        
})

Here's the demo这是演示

So...respond to a click on the checkbox setting disabled to false if the checkbox is ticked.所以...如果勾选了复选框,则响应单击disabledfalse的复选框设置。 In this example, I'm assuming you also want to set disabled to true if the checkbox is unticked again:在此示例中,我假设您希望在再次取消选中该复选框时将disabled设置为true

if((input=$("input:checkbox[name=checking]").is(":checked"))){
    $("#valide").prop('disabled',true); // <== You might want to make this depend on the initial state of the checkbox
}
input.on("click", function() {
    $("#valide").prop('disabled', !this.checked);
});

FIDDLE :小提琴

$(function () {
   $(':checkbox[name=checking]').click(function () {
      if ($(this).is(':checked')) $('#valide').prop('disabled', false);
   });
});

you must add listener to check box for call function every time when user check or uncheck it每次用户选中或取消选中它时,您都必须将侦听器添加到调用函数的复选框中

try this sloution :)试试这个 slotion :)

   <input type="checkbox" onclick="check()" name="checking">j'accepte les            conditions
   <input type="submit" value="Valider"  id="valide" disabled/>





     function check(){
    if($('input[name=checking]').is(":checked")){
        $("#valide").prop('disabled',false);
    }else{
    $("#valide").prop('disabled',true);
    }
    }

please be sure to add javascript code after your html code请务必在您的 html 代码后添加 javascript 代码

demo Click here演示点击这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM