You can use JavaScript to dynamically modify a list and its contents. This recipe shows you how to use JavaScript to add or remove list items in a read-only list.
Copy the full code of this recipe from the code/06/scripting-lists
sources folder. This code can be launched using the URL http://localhost:8080/06/scripting-lists/main.html
.
In
main.html
, add the following code to create an empty list in a layout grid:<div data-role='content'> <div data-role='fieldcontain'> <fieldset class='ui-grid-b'> <div class='ui-block-a' style='width: 65%'> <ul id='numlist' data-role='listview' data-theme='e' data-inset='true'> </ul> </div> <div class='ui-block-b'> <button data-theme='b' id='addBtn'>Add</button> <button data-theme='b' id='removeBtn'>Remove</button> </div> </fieldset> ...