我使用多页模板编写了我的第一个jquery移动网站。
在我的应用程序中,主页面中的更改可能会影响子页面下拉列表中的选定值。第一次进入子页面时,选择并显示正确的选项。之后,当我转到子页面时,正确的选项是选择(勾选),但显示错误的选项。
我创建了一个jsfiddle来演示这个... http://jsfiddle.net/afePj/2/
第一页允许您选择一个选项......
<select name="selectname1" id="selectid1" onChange="changePageTwo()">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
...并在第二页上设置所选值以匹配...
function changePageTwo() {
select1 = document.getElementById('selectid1');
select2 = document.getElementById('selectid2');
select2.selectedIndex = select1.selectedIndex;
}
...当你到达第二页时,我希望显示所选的值。但是在页面显示一次后,它显示的选项永远不会改变...
<select name="selectname2" id="selectid2">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
</select>
关于如何让子页面显示所选值的任何想法?
由于
答案 0 :(得分:3)
当你更新jQuery Mobile中的选择菜单时,你需要调用select menu widget's refresh菜单,以便更新显示以匹配原生元素
例如
$('selectid2').selectmenu('refresh');