如何检查“复选框”动态 - jQuery Mobile [英] How to check "checkbox" dynamically - jQuery Mobile

查看:84
本文介绍了如何检查“复选框”动态 - jQuery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTML复选框就是这样创建的:

 < 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中检查复选框/广播的正确方法。


Demo




  $ ('.selector')。prop('checked',true).checkboxradio('refresh'); 

参考: jQuery Mobile API


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.

Demo

$('.selector').prop('checked', true).checkboxradio('refresh');

Reference: jQuery Mobile API

这篇关于如何检查“复选框”动态 - jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆