在JavaScript中获取select中的选项值
在JavaScript中获取select中的选项值
这个问题已经有了答案:
可能的重复:
我需要做这个:
if(document.getElementById("short_code").options.item(document.getElementById("short_code").selectedIndex).text)== "First") //get the value of the option Fist , how to get the value?
admin 更改状态以发布 2023年5月20日
这怎么样:
var select = document.getElementById('short_code'); var options = select.options; var selected = select.options[select.selectedIndex]; //which means that: console.log(selected.value || selected.getAttribute('value'));//should log "12" console.log(selected.innerHTML);//should log(First);
遍历所有选项(可以创建参考变量,例如我的options
,或者使用for (var i=0;i