jQuery 移动设备,Select 在单击之前不显示所选选项
jQuery Mobile, Select not showing selected option until clicked
我正在尝试通过 ajax 将 <options>
添加到几个 <select>
中,当我直接将它们添加到 HTML 时工作正常,但是当我加载在 AJAX 中,只有单击 <select>
元素才会显示所选选项。
我已经尝试 .trigger('create')
所有元素甚至 .enhanceWithin()
但无济于事。
这个 jsfiddle 显示了问题:http://jsfiddle.net/3c01g6e2/1/
有什么帮助吗?
来自demo page (also see 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)
我正在尝试通过 ajax 将 <options>
添加到几个 <select>
中,当我直接将它们添加到 HTML 时工作正常,但是当我加载在 AJAX 中,只有单击 <select>
元素才会显示所选选项。
我已经尝试 .trigger('create')
所有元素甚至 .enhanceWithin()
但无济于事。
这个 jsfiddle 显示了问题:http://jsfiddle.net/3c01g6e2/1/
有什么帮助吗?
来自demo page (also see 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)