How to check “checkbox” dynamically - jQuery Mobile

前端 未结 3 822
一个人的身影
一个人的身影 2020-11-27 07:33

With HTML a checkbox is created like this:

Category1
<
相关标签:
3条回答
  • 2020-11-27 07:55

    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

    0 讨论(0)
  • 2020-11-27 08:01

    Straight from the jQ Mobile docs:

    $("input[type='checkbox']").attr("checked",true);
    
    0 讨论(0)
  • You can do:

    $('input[name="checkbox-0"]').prop("checked", true).checkboxradio('refresh'); //sets the checkbox
    var isChecked =  $('input[name="checkbox-0"]').prop("checked"); //gets the status
    
    0 讨论(0)
提交回复
热议问题