如何检查“复选框”动态 - jQuery Mobile [英] How to check "checkbox" dynamically - jQuery Mobile
问题描述
< form>
< input type =checkboxid =category1> Category1< br>
< / form>
使用javascript,我们可以检查复选框,如下所示:
$(#category1)[0] .checked = true
现在我正在尝试使用jquery-mobile创建相同的页面。复选框如下所示:
< form>
< label>
< input name =checkbox-0type =checkbox>检查我
< / label>
< / form>
这里为什么没有 id
?名称是 id
?我应该删除属性名称并使用名称 id
?
创建一个名称。如何在此处选中此复选框使用Javascript / jQuery的?
我试过了上面的代码,但它似乎不适用于这个复选框。
您需要使用 .checkboxradio('refresh')$>更改其
.prop
后刷新它C $ C>。这是在jQuery Mobile中检查复选框/广播的正确方法。
$ ('.selector')。prop('checked',true).checkboxradio('refresh');
With HTML a checkbox is created like this:
<form>
<input type="checkbox" id="category1">Category1<br>
</form>
With javascript we can check the checkbox like this:
$("#category1")[0].checked = true
Now I am trying to create the same page with jquery-mobile. The checkbox looks like this:
<form>
<label>
<input name="checkbox-0 " type="checkbox">Check me
</label>
</form>
Why is there is no id
here? Is the name the id
? Should I delete the attribute name and create one with the name id
?
How can I check this checkbox here with Javascript/jQuery?
I tried the code above, but it doesn't seem to work for this checkbox.
You need to refresh it after changing its' .prop
, using .checkboxradio('refresh')
. This is the correct way to check checkbox/radio in jQuery Mobile.
$('.selector').prop('checked', true).checkboxradio('refresh');
Reference: jQuery Mobile API
这篇关于如何检查“复选框”动态 - jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!