我正在尝试添加 <options>
到几个<select>
通过 ajax 动态地,当我直接在 HTML 中添加它们时工作正常,但是当我在 AJAX 中加载它们时,它们不会显示所选选项,直到 <select>
元素被点击。
我试过 .trigger('create')
在所有元素上,甚至 .enhanceWithin()
但无济于事。
这个 jsfiddle 显示了问题:http://jsfiddle.net/3c01g6e2/1/
有什么帮助吗?
最佳答案
来自demo page (另见 documentation ):
If you manipulate a select via JavaScript, you must call the refresh method on it to update the visual styling. Here is an example:
var myselect = $("select#foo"); myselect[0].selectedIndex = 3; myselect.selectmenu("refresh");
如果将 $("select").selectmenu("refresh");
添加到 fiddle 的末尾,它会正确更新。 (Updated Fiddle)
关于javascript - jQuery Mobile,选择在单击之前不显示选定的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30905664/