Home Web Front-end JS Tutorial How to set the default selected option based on the select tag?

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

Jun 02, 2018 am 09:54 AM
select set up default

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