This article mainly introduces the relative methods of select Drop-down box.
1. Get the value and text values of the dropdown box by ID
For example: <select class= "Form-control" id= "Numbers" >
<option value= "1" > Digital 1</option>
<option value= "2" selected> digital 2</option>
</select>
$ ("#numbers option:selected"). Val (); Gets the Optionde value value to which the Drop-down box is selected: 2;
$ ("#numbers option:selected"). Text (); Gets the Optionde text content that is selected to the dropdown box: number 2;
2. Select a select value by default: Increase the selected property
Enter a number in the input box, call the Selectnumber () method when you lose focus, and select the same number as the input box
function Selectnumber () {
var num = $ ("#num"). Val (); Get the number entered in input
var numbers = $ ("#numbers"). Find ("option"); Get all values for the Select Drop-down box
for (var j = 1; j < Numbers.length; J + +) {
if ($ (numbers[j]). val () = num) {
$ (Numbers[j]). attr ("Selected", "Selected");
}
}
}