js获取下拉列表框<option>中的value和text的值示例代码
在编程过程中,我们对下拉列表框的取值很多时候都是获取option中的value,但是也有需要获取显示在页面中的值的时候,例如想获得<option value="value">ShowText</option>中"ShowText",我们该如何获取呢?方法很简单,具体代码如下:
<script type="text/javascript">
function a(object){
alert(object);
}
</script><!-- 获取显示的值 -->
<select onchange="a(this.options[this.selectedIndex].innerText);">
<option value="value-a">text-a</option>
<option value="value-b">text-b</option>
</select><!-- 获取value的值 -->
<select onchange="a(this.options[this.selectedIndex].value);">
<option value="value-c">text-c</option>
<option value="value-d">text-d</option>
</select>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表单提交
}
}<select onchange="isSelect(this);" id="mySelect">
<option value="-1">--请选择--</option>
<option value="0">北京</option>
<option value="1">上海</option>
<option value="2">武汉</option>
</select>
您可能感兴趣的文章:
- js获取下拉列表框<option>中的value和text的值示例代码
- 使用js获取下拉列表框<option>中的value和text的值
- JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码)
- js javascript <select>根据value或text设置下拉列表的默认值
- js获取select选中的option的text示例代码
- JS,Jquery获取select,dropdownlist,checkbox下拉列表框的值(示例代码)
- js获取select选中的option的text示例代码
- JS获取下拉列表所选中的TEXT和Value的实现代码
- JS获取jQuery获取当前<input type="text" />的value--通过测试了
- JS获取DropDownList的value值与text值的示例代码
- JS获取DropDownList的value值与text值的示例代码
- JS获取DropDownList的value值与text值的示例代码
- JS获取下拉列表所选中的TEXT和Value的实现代码
- android中使用TextView来显示某个网址的内容,使用<ScrollView>来生成下拉列表框
- JS获取select-option-text_value的方法
- Lotusscript代理调用正则表达式过滤掉<html>代码,获取notesRichTextItem内容信息的方法
- 类库-----一些经常用到的对控件的处理1. 获取文本框中输入内容2.清除文本框内容3. 获取下拉列表框中选择内容,类型0为Text值,类型1为Value值4.DropDownList绑定日期
- JS 获取select(多选下拉)中所选值的示例代码
- JS给<select>的<option>赋值&JS发异步请求获取后台列表
- JS 获取select(多选下拉)中所选值的示例代码