JS Take value
Get the value of a drop-down list check
The code is as follows |
Copy Code |
function Getselectedvalue (name) { var Obj=document.getelementbyid (name); return obj.value; So simple, you can get the Value property of its object directly } |
Get text value
The code is as follows |
Copy Code |
<select id= "Select" > <option>1</option> <option selected= "Selected" >2</option> <option>3</option> </select> <script language= "javascript" type= "Text/javascript" > var Byid = document.getElementById ("select") Alert (Byid.options[byid.selectedindex].text) </script> |
Example 2
The code is as follows |
Copy Code |
<select id= "Select1" onchange= "ABC ()" > <option value= "1" > Reading </option> <option value= "2" > Sports </option> </select> <script type= "Text/javascript" > Function abc () { var obj =document.getelementbyid ("Select1"); alert (Obj.options[obj.selectedindex].text); } </script> |
jquery procedure
The code is as follows |
Copy Code |
$ ("#select option[selected]"). Text (); There are spaces between select and option, and option is the child element of select
$ ("#select option:selected"). Text (); |
If written as $ ("#select"). Text (), select all the Drop-down menu texts
Get value
The code is as follows |
Copy Code |
$ ("#select"). Val ();//Fetch value $ ("#select"). Val ("value");/setting, if there is an option in the select that has value values, the option is selected and if not, select does not |
Any changes