我在这里有这个复选框,我想要做的是启用按钮,如果选中了复选框,但它不起作用。
HTML:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" style="width:294px">
<input type="checkbox" name="checkbox-1" id="checkbox-1" class="chk"/>
<label for="checkbox-1">I agree</label>
</fieldset>
</div>
<input type="submit" id="submit" data-inline="true" data-theme="a" data-icon="check" value=" Submit " disabled/>
JavaScript的:
<script>
$('.chk').change(function(){
if ($(this).is(':checked'))
{
$("#submit").removeAttr("disabled");
}
else
{
$("#submit").attr( "disabled", "disabled" );
}
});
</script>
我看不出有什么问题。我正在使用JQM 1.3.2
答案 0 :(得分:1)
$('.chk').change(function(){
if($(this).is(':checked')) {
$('#submit').button('enable');
}
else {
$('#submit').button('disable');
}
});
答案 1 :(得分:1)
您需要使用.button()
小部件来启用或禁用按钮。
$(document).on("change", "#checkbox-1", function () {
if ($(this).prop("checked")) {
$("#submit").button("enable");
} else {
$("#submit").button("disable");
}
});
<强> Demo 强>
答案 2 :(得分:0)
使用button("enable")
和button("disable")
您正在使用jquery mobile,因为
$('.chk').change(function () {
if ($(this).is(':checked')) {
$("#submit").button('enable');
} else {
$("#submit").button('disable');
}
});
此处为fiddle
答案 3 :(得分:-2)
当你说:
$('object').is(':checked')
返回一个数字,即检查对象的数量。
因此,为了做你喜欢的事情,你应该有一个特定于对象的标识符 (#submit),你应该将你的if修改为以下内容。
$('#submit').is(':checked') > 0