获取select的text内容(jquery)

       在前端获取select的value比较容易,用getElementById('id')或jquery的$(#'id').val()就可,获取select的文本内容则需要用select对象的options[obj.selectedIndex].text,看js代码

 

<select id="test" name="cc" onchange="change()">
	<option value="1">10</option>
	<option value="2">20</option>
	<option value="3">30</option>
</select>
 

 

<script>
	function change(){
		
		//alert('seel');
		var sel = document.getElementById("test");
		alert(sel.value);
		var text = sel.options[sel.selectedIndex].text;
		alert(text);
		// jquery catch select text
		var checkText=$("#test").find("option:selected").text();   
		alert('jquery catch select text'+checkText);
		
	}
</script>
 

JQuery获取select的文本内容的表达式 $("#select_id").find("option:selected").text()

你可能感兴趣的:(jquery)