Home > Web Front-end > JS Tutorial > body text

How to set the default selected option based on the select tag?

亚连
Release: 2018-06-02 09:54:40
Original
1847 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 tag is:

var val = document.all.Item.options[document.all.Item.selectedIndex].text
var i=document.getElementById( 'sel' ).options[document.getElementById( 'sel' ).selectedIndex].value;
Copy after login

Some other techniques for operating the