html里如何獲取每次點擊select里的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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。