我正在用Jquery Mobile写一个网上商店,在那里我想使用一个选择菜单来浏览可用的类别。当用户选择一个类别时,我想导航到同一页,但要在url中添加几个参数。这是我的select标记:
<asp:Repeater id="productCatSelect" runat="server">
<HeaderTemplate>
<select id="productCatSelectMenu" data-native-menu="false" onchange="categoryClick();" class="button" data-theme="a">
<option data-placeholder="true">All Categories</option>
</HeaderTemplate>
<ItemTemplate>
<option value="<%# Eval("NodeID") %>" ><%# Eval("Description")%></option>
</ItemTemplate>
<FooterTemplate>
</select>
</FooterTemplate>
</asp:Repeater>
下面是javascript:
function categoryClick() {
var mySelect = $("#productCatSelectMenu");
if (mySelect.val() != '') {
if (mySelect.val() == 0) {
$.mobile.changePage("shop.aspx", {reloadPage: true, transition:"slide"});
} else {
$.mobile.changePage("shop.aspx?c=" + $("#productCatSelectMenu").val() + "&n=" + $('#productCatSelectMenu :selected').text(), {reloadPage: true, transition:"slide"});
}
}
}
当我导航一次并试图从select中选择另一个选项时,我的javascript仍然检索以前的值;select似乎没有重置!但是,当我按下F5并手动重新加载页面时,菜单会再次工作,当然,直到我使用过一次为止。
有谁知道我该怎么解决这个问题吗?正如您在javascript中看到的那样,"reloadPage: true“属性并不能解决这个问题。
发布于 2011-12-16 23:41:35
你需要自己重置它,也许可以试试:
$('select#productCatSelectMenu option').attr('selected', false);
或
$('select#productCatSelectMenu option').removeAttr('selected');
或
$('select#productCatSelectMenu').children('option').removeAttr('selected').filter(':nth-child(1)').attr('selected', true);
或
$('select#productCatSelectMenu').attr('selectedIndex', -1);
前几天我也遇到过类似的问题
发布于 2012-05-29 20:18:30
如果您使用的是jQuery Mobile的自定义选择字段,请尝试
$("#select_id").selectmenu('refresh', true)
这将成功地重置由jQuery mobile呈现的选择选项。
发布于 2014-11-07 18:19:27
我不知道为什么Jquery mobile select是这样工作的。除了这里提到的以外,上述所有方法都不适用于我。我使用的是当前版本的jquery-1.10.2.min.js jquery.mobile-1.4.2.min.js
https://forum.jquery.com/topic/resetting-select-menu
var myselect = $("select#useOfColor");
myselect[0].selectedIndex = 0;
myselect.selectmenu("refresh");
https://stackoverflow.com/questions/8534185
复制相似问题