JS/Jquery实现select选中option触发事件
js
<select id="pid" onchange="gradeChange()"> <option value="a">选项一</option> <option value="b">选项二</option> </select>
function gradeChange() { var myselect = document.getElementById("pid"); var index=myselect.selectedIndex; // selectedIndex代表的是你所选中项的index var value = myselect.options[index].value; console.log(value); }
jquery
<select id="select" > <option value="op1">option1</option> <option value="op2">option2</option> <option value="op3">option3</option> <option value="op4">option4</option> </select>
$('#select').change(function() {
    //一:
    console.log($(this).val());
    //二:
    var options=$("#select option:selected");
    console.log(options.val());
})
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号