jQuery Mobile 未在列表中显示正确的选定项目 [英] jQuery mobile not displaying correct selected item in list
问题描述
我有一个选择列表.我正在使用 jQuery 更新所选项目.当我更改所选值时,框中显示的项目不会更新.在下面的示例中,选项a"被设置为选中.然后我使用 jQuery 将所选项目更改为d".它仍然显示a".但是,如果您展开列表,您会看到d"被选中或突出显示.不知道如何解决这个问题.任何帮助将不胜感激!
HTML:
jQuery:
$(document).ready(function () {$('#d').prop('selected', 'selected');});
谢谢,布莱恩
首先,不要在 jQuery Mobile 中使用 .ready()
.
以编程方式选择选项时,您需要重新增强selectmenu小部件.
$("#id").prop("selected", true);$("select_id").selectmenu("刷新");
<块引用>
I have a select list. I am using jQuery to update the selected item. The displayed item in the box isn't updating when I change the selected value. In the following example option "a" is set as selected. Then I use jQuery to change the selected item to "d". It still shows "a". However if you expand the list you can see that "d" is selected or highlighted. Not sure how to fix the issue. Any help would be appreciated!
Html:
<select id="t">
<option>select one</option>
<option id="a" selected="selected">a</option>
<option id="b">b</option>
<option id="c">c</option>
<option id="d">d</option>
</select>
jQuery:
$(document).ready(function () {
$('#d').prop('selected', 'selected');
});
Thanks, Brian
First of all, refrain from using .ready()
in jQuery Mobile.
When selecting an option programmatically, you need to re-ehance selectmenu widget.
$("#id").prop("selected", true);
$("select_id").selectmenu("refresh");
这篇关于jQuery Mobile 未在列表中显示正确的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!