Jquery Mobile checkbox-list does not update when adding items and “refreshing” the script to style it

后端 未结 1 933
说谎
说谎 2021-01-25 09:51

It is very easy to add a checkbox list in JQuery Mobile, the scripts automatically style/change the following html and give it functionality:

相关标签:
1条回答
  • 2021-01-25 10:37

    Don't panic. As you are using jQuery Mobile, this also could be done very easy. First of all, you should set the structure of your page:

    <div data-role="page" id="page-1">
      <div data-role="main" class="ui-content">
          ...here goes your fieldset
      </div>
    </div>
    

    You should append the new checkbox inside the controlgroup container:

    $(document).on("pagecreate", "#page-1", function() {
        var item5 = $("<label for='checkbox-5a'>Flips</label><input type='checkbox' id='checkbox-5a'></input>"), 
            liste = $("#liste");
        liste.controlgroup("container").append(item5);
        $(item5[1]).checkboxradio();
        liste.controlgroup("refresh");
    });
    

    BTW, you may also use $(document).on("pagecreate") instead of $(document).ready.

    0 讨论(0)
提交回复
热议问题