javascript 使用 javasccript 将下拉控件重置为默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8529381/
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
reset dropdown control to default value using javasccript
提问by happysmile
i have div tag inside the div tag i have an drop down control which is binded to the database values https://stackoverflow.com/questions--select-- india us Auz
我在 div 标签中有 div 标签我有一个下拉控件,它绑定到数据库值 https://stackoverflow.com/questions--select-- india us Auz
i have an checkbox control once i check then this the div tag will be visable uncheck the checkbox theen div tag will be invisable.
我有一个复选框控件,一旦我检查,那么这个 div 标签将是可见的,取消选中复选框,然后 div 标签将是不可见的。
if the user select some value in the dropdown control like "AUZ" again if user checks or unchecks the checkbox it should always show first value "--select--"
如果用户再次选择下拉控件中的某个值,例如“AUZ”,如果用户选中或取消选中该复选框,则应始终显示第一个值“--select--”
hope my Question is clear
希望我的问题很清楚
can any one give the syntax how to achieve, any help would be appreciated.
任何人都可以给出如何实现的语法,任何帮助将不胜感激。
Thanks
谢谢
回答by Adam Rackis
To reset your dropdown, select its first option, and set the selected attribute to true.
要重置下拉列表,请选择其第一个选项,并将 selected 属性设置为 true。
$("#yourSelectId option:first").attr("selected", true);