Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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
Jquery 提交按钮灰显,直到勾选复选框为止?_Jquery_Html_Validation_Checkbox - Fatal编程技术网

Jquery 提交按钮灰显,直到勾选复选框为止?

Jquery 提交按钮灰显,直到勾选复选框为止?,jquery,html,validation,checkbox,Jquery,Html,Validation,Checkbox,我正在试图找出如何在取消勾选复选框时灰显提交按钮?谁能把我引向正确的方向 html: 为什么不在点击事件中这样做 $(document).ready(function() { $('#submit').prop('disabled', true); // disabled by default $('#checkbox').click(function() { // change on checkbox click $('#submit').pr

我正在试图找出如何在取消勾选复选框时灰显提交按钮?谁能把我引向正确的方向

html:


为什么不在点击事件中这样做

$(document).ready(function() {


    $('#submit').prop('disabled', true); // disabled by default

    $('#checkbox').click(function() {
       // change on checkbox click
       $('#submit').prop('disabled', !$('#checkbox').prop('checked'));
    });

});

为什么不在点击事件中这样做

$(document).ready(function() {


    $('#submit').prop('disabled', true); // disabled by default

    $('#checkbox').click(function() {
       // change on checkbox click
       $('#submit').prop('disabled', !$('#checkbox').prop('checked'));
    });

});
嗨,请试试这个

if($("#checkkBoxId").attr("checked"))
{
    alert("Checked");
     $('#submit').attr('disabled','false');
}
else
{
    alert("Unchecked");
    $('#submit').attr('disabled','true');
}
嗨,请试试这个

if($("#checkkBoxId").attr("checked"))
{
    alert("Checked");
     $('#submit').attr('disabled','false');
}
else
{
    alert("Unchecked");
    $('#submit').attr('disabled','true');
}

对于布尔属性值,请使用
.prop()
而不是
.attr()
对于布尔属性值,请使用
.prop()
而不是
.attr()
感谢您的回复,默认情况下,“提交”按钮现在变灰,但不取决于是否勾选了复选框?无论我是否勾选复选框,它都会保持灰色。请检查我所做的编辑。非常感谢您的回复,提交按钮现在默认为灰色,但不取决于是否勾选复选框?无论我是否勾选复选框,它都会保持灰色。请检查我所做的编辑。它能纠正你的情况吗?很好,非常感谢
$('#myform').on('change', ':checkbox', function() {
      If($(this).is(':checked')) {
           $(this).closest('#myform').find('#submit').attr('disabled', false);
      } 
      else{
            $(this).closest('#myform').find('#submit').attr('disabled', true);
 });