select 中 option 的选中事件

来源:互联网 发布:淘宝关键词提取器 编辑:程序博客网 时间:2024/05/17 07:49

//使用 jquery 获取 selected 的选中事件

<select id=“selected1”>

<option>你</option>

<option>我</option>

</select>

<script>

$(function(){

$("selected1").change(function(){

alert($(this).val());

});

});

</script>


//使用 js 获取 selected 的选中事件

<select id="selected2" onchange=“selected()”>

<option>你们</option>

<option>我们</option>

</select>

<script>

function selected(){

var sel=document.getElementById("selected2");

var var=sel.options[sel.selectedIndex].value;

alert(var);

}

</script>


原创粉丝点击