JQuery mobile - Update checkboxes using pageinit

I am invoking a page (see code below) from a list of links on another page using. List like this

<ul data-role="listview" data-theme="g"> <li><a href="test.html">test</a></li> </ul> 

with the code below being the test.html page.

I use jquery mobile on these pages. Only the flags after the first 3 flags appear updated (appear as marked) when the page is loaded by clicking on the link. The first three flags always seem unselected, and their checked value is set to false. Unusually, if I put an if statement right after the statement that sets the flag to true, the checked flag is checked for true, but on the displayed page it looks false, and you look at the checked value in the element area of โ€‹โ€‹the web inspector. When you refresh the page (using F5 or the refresh button next to the address bar), the check boxes are updated as you expected. Any help would be greatly appreciated. While the code example below just sets all the checkboxes for the checked value, I really (on my real page) set their value based on the data from the recordset, so I canโ€™t just set the mass parameter to true and refresh. I need to scroll through the recordset and set the checkbox values โ€‹โ€‹accordingly. The code below is just a reproduction of the error I have. Thanks!

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Checkbox</title> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1"> <link rel="stylesheet" href="jqm1/jquery.mobile.structure-1.0.1.min.css" /> <script src="jqm/jquery-1.7.1.min.js"></script> <script src="jqm/jquery.mobile-1.0.1.min.js"></script> </head> <body> <div id="loadCB" data-role="page"> <script type="text/javascript"> $("#loadCB").live('pageinit', function() { // do something here... for (i=0;i<=5;i++) { $("#checkbox-"+i).prop("checked", true); $("#checkbox-"+i).prop("checked", true).checkboxradio("refresh"); } }); </script> <article data-role="content"> <form id="frmR"> <input type="checkbox" name="checkbox-0" id="checkbox-0" class="custom" value="0"/> <label for="checkbox-0">checkbox-0</label> <input type="checkbox" name="checkbox-1" id="checkbox-1" class="custom" value="1"/> <label for="checkbox-1">checkbox-1</label> <input type="checkbox" name="checkbox-2" id="checkbox-2" class="custom" value="2"/> <label for="checkbox-2">checkbox-2</label> <input type="checkbox" name="checkbox-3" id="checkbox-3" class="custom" value="3"/> <label for="checkbox-3">checkbox-3</label> <input type="checkbox" name="checkbox-4" id="checkbox-4" class="custom" value="4"/> <label for="checkbox-4">checkbox-4</label> <input type="checkbox" name="checkbox-5" id="checkbox-5" class="custom" value="5"/> <label for="checkbox-5">checkbox-5</label> <input type="submit" value="Set Rules" /> </form> </article> </body> </div> </html> 
+6
source share
2 answers

Check this code

 $("#loadCB").live('pageinit', function() { // do something here... $("input[type='checkbox']").attr("checked",false).checkboxradio("refresh"); }); 
+6
source

I wrote a fairly complete list of widgets and a method for updating them: http://andymatthews.net/read/2011/12/14/Refreshing-jQuery-Mobile-listviews,-buttons,-select-dropdowns,-and-input-fields

Perhaps this will answer your question?

+3
source

Source: https://habr.com/ru/post/908868/


All Articles