js获取下拉列表框

WBOY
Release: 2016-05-16 17:04:23
Original
1470 people have browsed it

在编程过程中,我们对下拉列表框的取值很多时候都是获取option中的value,但是也有需要获取显示在页面中的值的时候,例如想获得中"ShowText",我们该如何获取呢?方法很简单,具体代码如下:

复制代码代码如下:



function isSelect(selectPress) {
//var select = document.getElementById("mySelect").ind;
var selectValue = selectPress.options[selectPress.selectedIndex].value; //显示value 下标0、1、2
var selectValue2 = selectPress.options[selectPress.selectedIndex].innerText; //显示显示的值 具体内容(上海、北京)
//alert(selectValue);
//alert(selectValue2);
if (selectValue == "-1") {
alert("请选择城市,表单提交被拒绝!")
return;
}
else {
document.getElementById('form1').submit(); //form表单提交
}
}


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Chrome doesn't apply padding to select options Select option padding not working in Chrome