Jquery 提交按钮灰显,直到勾选复选框为止?
我正在试图找出如何在取消勾选复选框时灰显提交按钮?谁能把我引向正确的方向 html: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
为什么不在点击事件中这样做
$(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);
});