<label for="swicher" class="ui-hidden-accessible">Notification:</label> <select data-track-theme="b" data-theme="c" name="swicher" id="swicher" data-role="slider" data-mini="true" onchange="onNotification(this)"> <option value="off">Off</option> <option value="on" selected>On</option> </select>
动态时需要jquery选择:
var storeNotification="on";
$("#swicher option[value='"+storeNotification+"']").attr("selected",true);
如果只写上面这句话时,不会有任何效果,需要加上下面这句:
$('#swicher').slider("refresh");
事实上,很多JQM控件在动态添加或删除时都有这样的问题,需要及时"refresh"。
见 http://hi.baidu.com/life_to_you/item/bf3621365fa5974b033edcbc
下面是selectmenu的“refresh”
<fieldset data-role="controlgroup" > <select name="month" id="month" data-native-menu="true" data-theme="b"> <option value='' disabled selected>Month</option> </select> <select name="day" id="day" data-native-menu="true" data-theme="b"> <option value='' disabled selected>Day</option> </select> <select name="year" id="year" data-native-menu="true" data-theme="b"> <option value='' disabled selected>Year</option> </select> </fieldset>
var d = new Date(); var year=d.getFullYear(); var month=d.getMonth()+1; var day=d.getDate(); // log(year+"-"+month+"-"+day); var days=31; $("#change_birthday_page #month").empty(); $("#change_birthday_page #month").append("<option value='' disabled selected>Month</option>"); for(var i=1;i<13;i++){ $("#change_birthday_page #month").append("<option value='"+i+"'>"+i+"</option>"); } $("#change_birthday_page #day").empty(); $("#change_birthday_page #day").append("<option value='' disabled selected>Day</option>"); for(var i=1;i<days+1;i++){ $("#change_birthday_page #day").append("<option value='"+i+"'>"+i+"</option>"); } $("#change_birthday_page #year").empty(); $("#change_birthday_page #year").append("<option value='' disabled selected>Year</option>"); for(var i=1970;i<year;i++){ $("#change_birthday_page #year").append("<option value='"+i+"'>"+i+"</option>"); } $("#change_birthday_page #month").selectmenu( "refresh" ); $("#change_birthday_page #day").selectmenu( "refresh" ); $("#change_birthday_page #year").selectmenu( "refresh" );
navbar动态生成不刷新?
http://blog.csdn.net/danielinbiti/article/details/27333311