admin管理员组文章数量:1287598
I have tried many ways to select an option with jquery including .val("0")
.attr('selected', 'selected')
and .attr('selected', 'true')
and the TexoTela plugin. They all seem to update the html but the browser still shows the last item selected by the user.
Try out this fiddle... Select the dropdown value 1 and then click the link.
Is there any way to actually update the displayed value?
I have tried many ways to select an option with jquery including .val("0")
.attr('selected', 'selected')
and .attr('selected', 'true')
and the TexoTela plugin. They all seem to update the html but the browser still shows the last item selected by the user.
Try out this fiddle... Select the dropdown value 1 and then click the link.
Is there any way to actually update the displayed value?
Share Improve this question edited Apr 24, 2013 at 9:20 Shikiryu 10.2k9 gold badges52 silver badges76 bronze badges asked Jun 3, 2011 at 3:03 user472749user472749 4591 gold badge5 silver badges13 bronze badges3 Answers
Reset to default 8You mean change which item is selected?
$('select').val('0');
There are other ways, but this is the basic, following your example.
jsfiddle
You can read up on the documenation for .val()
here, and the snippet:
checks, or selects, all the radio buttons, checkboxes, and select options that match the set of values.
EDIT for jQuery Mobile
For jQuery Mobile you also need to refresh the select as mentioned in the mobile docs:
If you manipulate a select via JavaScript, you must call the refresh method on it to update the visual styling.
You can do this by:
$('select').selectmenu("refresh",true);
You're setting the option value to zero.
Set the select not the option val
$('select').val('0');
and you'll probably want to use an #id instead just a 'select' selector.
Still use your .val("0")
to set the value, and to update in the browser you have to use one of the following:
.trigger("liszt:updated");
or
.trigger("chosen:updated");
Just one will work, depending on how you create your select.
It's gonna be like:
$("#Your_select").val('0');
$("#Your_select").trigger("liszt:updated");
本文标签: javascriptHow to change rendered selected option in select box with jqueryStack Overflow
版权声明:本文标题:javascript - How to change rendered selected option in select box with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741264789a2368255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论