Home >Web Front-end >JS Tutorial >Detailed explanation of how to set the default selection of the select tag

Detailed explanation of how to set the default selection of the select tag

小云云
小云云Original
2018-03-03 09:12:082261browse

This article mainly shares with you an option method for setting the default selected option of the select tag. It has a good reference value and I hope it can help everyone.

There are two methods.

The first method is to set the selected item through the attribute of label is:

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

Some others The techniques for operating the