JavaScript获取Select当前值写法:
var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text;
ตัวอย่าง:
复制代码代码如下:
<สคริปต์>
ตรวจสอบฟังก์ชัน () {
var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
การแจ้งเตือน (เลือก);
-
</สคริปต์>
<select name="select" id="select">
<option value="test1" Selected="selected">ทดสอบ1</option>
<option value="test2">ทดสอบ2</option>
</เลือก>
<input type="button" value="我要试试" onclick="check()"/>