原生js获取select的option项的label和value值
来源:互联网 发布:ubuntu安装numpy 编辑:程序博客网 时间:2024/05/22 12:28
1.利用原生js获取select选中option项的值和文本
2.将select的选中值和文本绑定到了两个文本框上
源码:
<!DOCTYPE html>
<html>
<head>
<title>select的取值</title>
</head>
<body>
<div>
国家
<select id="country" onchange="getVal()">
<option selected="selected" value="China">中国</option>
<option value="Canada">加拿大</option>
<option value="India">印度</option>
</select>
label:<input type="text" id="myLabel" readonly="readonly" />
value:<input type="text" id="myValue" readonly="readonly"/><br>
</div>
</body>
</html>
<script type="text/javascript">
//给label和value设置初值
window.onload = getVal();
//select的onchange调用函数
function getVal(){
var countrySelect = document.getElementById('country');//获取select的dom
var index = countrySelect.selectedIndex;//获取选中的index
var label = countrySelect.options[index].text; //获取标签值
var value = countrySelect.options[index].value;//获取value值
document.getElementById('myLabel').value = label;
document.getElementById('myValue').value = value;
}
</script>
- 原生js获取select的option项的label和value值
- Select 的绑定值为对象类型时用法 同时获取option选项的label和value值
- js实例,获取选中select标签的value和option text值
- 获取select中option的value值
- 下拉列表select动态添加option和获取选中的option的值和value
- js中获取select 中 option 的文字test和值value js方式和jquery方式
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和 Value(转)
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和 Value(转)
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jquery 获取Select option 选择的Text和Value
- 【转载】jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- jQuery获取Select option 选择的Text和Value
- 定位:static、fixed、relative、absolute
- 计算两日期相差几天
- submit,re,eval
- 深入了解MyBatis参数
- lintcode -- 线段树的构造
- 原生js获取select的option项的label和value值
- POJ
- 汉诺塔问题
- 术--经典题解析(1)
- CSS盒子模型和部分选择器
- Oracle中通过substr和instr实现截取指定字符之间的字符串:
- luogu1967 货车运输
- 自定义控件三部曲之绘图篇——Path之贝赛尔曲线和手势轨迹、水波纹效果
- java读书笔记-Thread类