js获取html select当前选中值代码:
1
|
<!doctype html> <html> <head> <meta charset="UTF–8"> <title>js获取html select当前选中值–www.02405.com</title> </head> <body> <select id="user" onchange="showSelect()"> <option value="zhangsan">张三</option> <option value="lisi">李四</option> <option value="wangwu">王五</option> </select> <script type="text/javascript"> function showSelect(){ var obj = document.getElementById("user"); var index = obj.selectedIndex;//当前select选中项的索引 console.log(obj.options[index].value);//输出当前select选中项的value console.log(obj.options[index].text);//输出当前select选中项的text } ipt> |