[英]jQuery mobile enable button if checkbox is checked
I have this checkbox here and I'm trying to do is to enable the button if checkbox is checked but it is not working. 我在这里有此复选框,我想做的是如果复选框已选中但不起作用,则启用该按钮。
HTML: 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: JavaScript的:
<script>
$('.chk').change(function(){
if ($(this).is(':checked'))
{
$("#submit").removeAttr("disabled");
}
else
{
$("#submit").attr( "disabled", "disabled" );
}
});
</script>
I can't see what's the problem. 我看不出有什么问题。 And I'm using JQM 1.3.2 我正在使用JQM 1.3.2
$('.chk').change(function(){
if($(this).is(':checked')) {
$('#submit').button('enable');
}
else {
$('#submit').button('disable');
}
});
When you say: 当你说:
$('object').is(':checked')
It returns a number, the number of the objects that are checked. 它返回一个数字,即已检查对象的数量。
So, for doing things like what you are, you should have an object specific identifier (#submit), and you should revise your if to something like the following. 因此,为了执行类似您自己的操作,您应该具有一个特定于对象的标识符(#submit),并且应该将if修改为以下内容。
$('#submit').is(':checked') > 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.