gpt4 book ai didi

jQuery Mobile 更改下拉所选选项并刷新它

转载 作者:行者123 更新时间:2023-12-03 22:06:31 24 4
gpt4 key购买 nike

我正在编写 jQuery 移动应用程序。我正在通过以下语句更改下拉选择的选项:- $("#DataBaseNames").val(db);

我确信传递了正确的数据库值,因为我通过警报检查了它。当我深入下拉菜单时,它还显示所选的正确文本,但下拉菜单本身未显示所选的正确文本。

我需要插入任何刷新调用吗?

编辑:-添加代码,下面来自 Phill 的答案解决了它

<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 ofoptions in the select are different than the number of items in thecustom menu, it'll rebuild the custom menu. Also, if you pass a trueargument you can force the rebuild to happen.

//refresh value         
$('select').selectmenu('refresh');

//refresh and force rebuild
$('select').selectmenu('refresh', true);

文档:

关于jQuery Mobile 更改下拉所选选项并刷新它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8153226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com