How to set the default selected option based on the select tag?
亚连
Release: 2018-06-02 09:54:40
Original
1901 people have browsed it
Below I will share with you an article on how to set the default selected option for the select tag. It has a good reference value and I hope it will be helpful to everyone.
There are two methods.
##The first sets the selected item through the attribute of
< select id = "sel" >
< option value = "1" >1</ option >
< option value = "2" selected = "selected" >2</ option >
< option value = "3" >3</ option >
</ select >
Copy after login
The second type is to control the selected item through front-end js:
< script type = "text/javascript" >
function change(){
document.getElementById("sel")[2].selected=true;
}
</ script >
< select id = "sel" >
< option value = "1" >1</ option >
< option value = "2" >2</ option >
< option value = "3" >3</ option >
</ select >
< input type = "button" value = "修改" onclick = "change()" />
Copy after login
The js code to get the text of the selected item in the
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn