Two methods to get the value of the option selected in the select drop-down box

The first

<select name="type" id="aaa" οnchange="show_sub()">    
    <option value="0">请选择主菜名</option>    
    <option value="1">白菜</option>    
    <option value="2">萝卜</option>    
 </select> 
 


 js code

 function show_sub(){     
	       alert($("#aaa").find("option:selected").attr("value"));//原生  
	        alert($("#aaa").find("option:selected").val());  //加入jq库

	    } 





The second 


<select name="type" οnchange="show_sub(this.options[this.options.selectedIndex].value)">    
    <option value="0">请选择主菜名</option>    
    <option value="1">白菜</option>    
    <option value="2">萝卜</option>    
 </select>

js code

<script>     
    function show_sub(v){     
        alert(v);     
    }     
</script>  



Both effects are the same





Guess you like

Origin blog.csdn.net/a447332241/article/details/77319006