我有一个自动完成组合框,其中包含来自 mysql 的选项,该组合框包含供应商的名称及其 id,其中一旦用户从组合框中选择,该 id 将存储在隐藏字段中,然后存储在 session 中。我想知道的是如何设置基于 session 的自动完成组合的默认文本/值?
例如。 session = 25;供应商文本 =“Stackoverflow”ID = 25 当用户单击新选项卡时,页面将自动显示组合框,其中包含基于 session 的适当文本。在这种情况下,组合框应具有 Stackoverflow 的文本值。实际上只要能够显示文本就足够了。
先生/女士,您的回答将会很有帮助。
最佳答案
我发现创建组合框时具有“selected”属性的选项将在组合框中被选中。您可以通过销毁组合框、从选项中删除“选定”属性并将该属性添加到要选择的选项中,然后再次创建组合框来设置选定选项。
这是我的代码:
// Destroy the combobox
$(".combobox").combobox("destroy");
// Unselect the currently selected option
$("#selectlist option:selected").removeAttr("selected");
// Select the option you want to select
$("#selectlist option[value='test']").attr("selected", "selected");
// Create the combobox again
$(".combobox").combobox();
关于jquery - 如何设置 jquery ui 组合框选定值或默认文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9458430/