您的位置:首页 > Web前端 > JavaScript

【js】selector值改变时显示当前选中option值

2016-02-23 00:49 627 查看
当selector值改变时,显示改后的option值:

<select id="seletor" onChange="route()">
	<option value="0">A</option>
	<option value="1">B</option>
	<option value="2">C</option>
</select>


function route(){
        var selector = document.getElementById("seletor");	
        var text = selector.options[selector.selectedIndex].text;
        var value = selector.options[selector.selectedIndex].value;
        alert(value + ":" + text);
}


PS: jQuery中:

var text = $("#selector")[0].options[$("#selector")[0].selectedIndex].text
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: