我正在编写jQuery Mobile App.
我正在通过以下语句更改下拉选择选项:
$( “#DataBaseNames”)VAL(DB).
我正在通过以下语句更改下拉选择选项:
$( “#DataBaseNames”)VAL(DB).
我确定正确的数据库值被传递,因为我通过警报检查.
当我向下钻取下拉列表时,它还显示所选的正确文本,但下拉列表本身没有显示正确的文本.
任何刷新电话我需要插入?
<script type="text/javascript"> $("#@ViewBag.DivTitle").live('pageshow',function () { var db = getCookie("DataBaseNames"); $("#DataBaseNames").val(db); $("#DataBaseNames option[value='"+ db + "']").attr("selected","selected"); // refresh value,Following is what is required $('select').selectmenu('refresh'); $("#cmdlogon").live("click",function () { var dbSelected = $("#DataBaseNames option:selected").text(); setCookie('DataBaseNames',dbSelected); }); }); function setCookie(name,value) { var expires = ""; document.cookie = name + "=" + value + expires + "; path=/"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } </script>
解决方法
refresh update the custom select
This is used to update the custom select to reflect the native select element’s value.If the number of
options in the select are different than the number of items in the
custom menu,it’ll rebuild the custom menu. Also,if you pass a true
argument you can force the rebuild to happen.
//refresh value $('select').selectmenu('refresh'); //refresh and force rebuild $('select').selectmenu('refresh',true);
文档:
> http://jquerymobile.com/demos/1.0rc3/docs/forms/selects/methods.html