如何用jquerymobile开发webapp
jQuery Mobile是一个基于jquery的html 5移动网站框架,用它做出来的网站界面和App风格类似。jQuery Mobile文档,内容不多,耐心看完只需要1个小时,大体分成8大功能点page:最基准单元,包括header,footer,导航栏dialog:对话框,在手机屏幕弹出dialog来交互,我觉得不是很友好transitions:转场效果form:表单button:大button,小button(放在各种栏上的都是小button),还提供了若干内置标准iconlistview:列表,这是jquery mobile的核心UI,提供了10几种类型的List,简单好用event:各种滚动,滑动,拖拽事件Theming:官方提供了5种皮肤,也有工具可以自定义,切换皮肤只需要改动一个classjQuery Mobile全面支持ajax,但也可以当做普通html模板在后端渲染数据,我选择后面一种
jQuery通用的全局遍历方法$.each()用法实例
1.test.json文件代码:
[
{
"username": "张三",
"content": "沙发."
},
{
"username": "李四",
"content": "板凳."
},
{
"username": "王五",
"content": "地板."
}
]
2.html代码:
<p>
<input type="button" id="send" value="加载"/>
</p >
<div >已有评论:</div>
<div id="resText" ></div>
3.jQuery代码:
<script src="jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
/*
1.$.each()是jquery的一个通用的遍历方法,可用于遍历对象和数组
2.$.each()函数不同于jquery对象的each()方法,它是一个全局函数,不操作jquery对象,而是以一个数组或者对象作为第一个参数,以一个回调函数作为第二个参数。回调函数拥有两个参数:第一个参数为对象的成员或数组的索引,第二个参数为对应变量或内容
*/
$(function(){
$('#send').click(function() {
$.getJSON('test.json', function(data) {
$('#resText').empty();
var html = '';
$.each( data , function(commentIndex, comment) {
html += '<div ><h6>' + comment['username'] + ':</h6><p >' + comment['content'] + '</p ></div>';
})
$('#resText').html(html);
})
})
})
</script>
还没有评论,来说两句吧...