HTML中option的单页调用

我们在用到下拉列表框select时,需要对选中的<option>选项触发事件,其实<option>本身没有触发事件方法,我们只有在select里的 onchange方法里触发。

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<select id="pid" onchange="gradeChange()">

    <option value="北京">北京</option>

    <option value="上海">上海</option>
</select>
<script src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    function gradeChange(){
        var checkText=$("#pid").find("option:selected").text();
        alert(checkText);
    }
</script>
</body>
</html>

 

posted @ 2017-12-11 15:34  kingrain  阅读(221)  评论(0编辑  收藏  举报