Thursday, January 12, 2012

jQuery Mobile: listview with data-filter

In the last exercise "jQuery Mobile: Add HTML elements using Javascript code", we insert the <ul> elements as standard html element, not natural jQuery Mobile element.

It's modify to jQuery Mobile "listview", with data-filter set "true":
<ul id="myitems" data-role="listview" data-filter="true" data-inset="true" >
</ul>

jQuery Mobile: listview
jQuery Mobile: listview with data filtered

<!doctype html>
<head>
<title>Mobile-Web-App: Add HTML elements using jQuery Mobile</title>
<meta charset="utf-8">
<meta name = "viewport" content = "width = device-width, height = device-height" />

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>


<script>
function myOnLoad(){
var myButton1 = document.getElementById("Button1");
myButton1.onclick = Button1Listener;
}

function Button1Listener(){
var myText1 = document.getElementById("Text1");
var myInput1 = myText1.value;

var newItem = document.createElement("li");
newItem.innerHTML = myInput1;
var myItems = document.getElementById("myitems");
myItems.appendChild(newItem);

}

window.onload = myOnLoad;

</script>


</head>
<body>

<div data-role="page" id="home">
<div data-role="header">
<h1>jQuery Mobile: Add HTML elements using Javascript code</h1>
</div>

<div data-role="content">
<p>Enter new item</p>
<form>
<input type="text" id="Text1">
<input type="button" id="Button1" value="Add">
</form>
<ul id="myitems" data-role="listview" data-filter="true" data-inset="true" >
</ul>
</div>

<div data-role="footer">
<h4><a href="http://mobile-web-app.blogspot.com/">http://mobile-web-app.blogspot.com/</a></h4>
</div>

</div>

</body>
</html>



Remark: we also hard-code jQuery Mobile css link and script pointing to the latest released version.


Related article:
- jQuery Mobile: ul element, with data-role="listview"

No comments:

Post a Comment