jqueryMobile 动态添加元素,展示刷新视图的实现方法
jQueryMobile的是一个很好的移动开发框架,你可能已经知道,虽然它有很多难以解决的问题,但是我相信后续版本jquery会修复……我是很喜欢jquery的。这并不是说它很完美无暇,很多开发人员遇到的情况也都难解决,比如:尝试使用代码来添加,更新或删除元素,使用JavaScript的页面跳转。在这篇博客文章中,我列出了一些动态添加组建重新刷新的方法。
1.Textareafield
$('body').prepend('<textareaid="myTextArea"></textarea>');
$('#myTextArea').textinput();
2.Textinputfield
$('body').prepend('<inputtype="text"id="myTextField"/>');
$('#myTextField').textinput();
3.button
$('body').prepend('<inputtype="text"id="myTextField"/>');
$('#myTextField').textinput();
3.Comboboxorselectdropdowns
<labelfor="sCountry">Country:</label>
<selectname="sCountry"id="sCountry">
<optionvalue="">WhereYouLive:</option>
<optionvalue="ad">Andorra</option>
<optionvalue="ae">UnitedArabEmirates</option>
</select>
varmyselect=$("#sCountry");
myselect[0].selectedIndex=3;
myselect.selectmenu('refresh');
4.最常见的动态添加listview>li标签
<ulid="myList"data-role="listview"data-inset="true">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
$('#mylist').listview('refresh');
5.Slidercontrol
<divdata-role="fieldcontain">
<labelfor="slider-2">Inputslider:</label>
<inputtype="range"id="slider-2"value="25"min="0"max="100"/>
</div>
$('#slider-2').val(80).slider('refresh');
6.Toggleswitch
<span><divdata-role="fieldcontain">
<labelfor="toggle">Flipswitch:</label>
<selectname="toggle"id="toggle"data-role="slider">
<optionvalue="off">Off</option>
<optionvalue="on">On</option>
</select>
</div>
varmyswitch=$("#toggle");
myswitch[0].selectedIndex=1;
myswitch.slider("refresh");</span>
7.Radio
<span><divdata-role="fieldcontain">
<fieldsetdata-role="controlgroup"data-type="horizontal">
<legend>Layoutview:</legend>
<inputtype="radio"name="radio-view"value="list"/>
<labelfor="radio-view-a">List</label>
<inputtype="radio"name="radio-view"value="grid"/>
<labelfor="radio-view-b">Grid</label>
<inputtype="radio"name="radio-view"value="gallery"/>
<labelfor="radio-view-c">Gallery</label>
</fieldset>
</div>
$("input[value=grid]").attr('checked',true).checkboxradio('refresh');</span>
8.Checkboxes
<divdata-role="fieldcontain">
<fieldsetdata-role="controlgroup">
<legend>Agreetotheterms:</legend>
<inputtype="checkbox"name="checkbox-1"id="checkbox-1"class="custom"/>
<labelfor="checkbox-1">Iagree</label>
</fieldset>
</div>
$('#checkbox-1').attr('checked',true).checkboxradio('refresh');
还有很多还需要慢慢发现!我做的是一个移动点餐系统:目前产品界面显示如下图:不知道有没有谁自己封装的listview,或者号的插件推荐我使用的!或有更好的建议……欢迎发表。
以上这篇jqueryMobile动态添加元素,展示刷新视图的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。