如何使用 javascript 更改 jquery selectric 元素的选定选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24437866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you change the selected option of a jquery selectric element using javascript?
提问by Mike Hensley
I can change the original select's selected option by doing something like-
我可以通过执行以下操作来更改原始选择的选定选项 -
$('#mySelectList option:first').prop('selected', true)
but that doesn't update the selectric display of the select.
但这不会更新选择的 selectric 显示。
回答by Felix Kling
According to this pull request, you can "refresh" the plugin:
根据此拉取请求,您可以“刷新”插件:
$('#mySelectList').prop('selectedIndex', 0).selectric('refresh');
From the documentation:
从文档:
$('select').selectric('refresh'); // Reconstruct the instance of plugin
$('select').selectric('refresh'); // Reconstruct the instance of plugin
回答by Alph.Dev
To change selectric by it's value, this works:
要通过它的值改变 selectric,这有效:
$('#mySelectList').val(someValue).selectric('refresh');