JS更改select内option属性的方法
作者:w93223010
这篇文章主要介绍了JS更改select内option属性的方法,涉及JavaScript动态操作页面select元素属性的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了JS更改select内option属性的方法。分享给大家供大家参考。具体如下:
帮一位友人解决了一个小问题,需求是更改选中选项卡内显示的文本值,新值存放在某个文本框内
初始窗口:
<html>
<head>
<title>原窗口</title>
<script>
var parentValue=""; //全局变量,用于保存点击详情时select中指定opeion的值
function detail() {
var select=document.getElementById('SHGX'); //获得select对象
parentValue=select.options[select.selectedIndex].text;
window.open('详情窗口.html')
}
function updateSelect(childValue) {
var select=document.getElementById('SHGX');
for(var i=0;i<select.length;i++) {
if(select.options[i].text==parentValue)
select.options[i].text=childValue;
}
}
</script>
</head>
<body>
<select id='SHGX'>
<option value='111' title='夫'>夫</option>
<option value='112' title='妻'>妻</option>
<option value='120' title='子'>子</option>
<option value='121' title='独生子'>独生子</option>
<option value='122' title='继子'>继子</option>
<option value='128' title='女婿'>女婿</option>
</select>
<button onclick="detail(); ">详情</button>
</body>
</html>
详情窗口:
<html>
<head>
<title>详情窗口</title>
<script>
function modify() {
var childValue=document.getElementById('text_01').value;
opener.updateSelect(childValue); //调用父窗口的函数
}
</script>
</head>
<body>
<input id="text_01" type="text" value=""/>
<button onclick="modify();">修改</button>
</body>
</html>
希望本文所述对大家的JavaScript程序设计有所帮助。
您可能感兴趣的文章:
- javascript Select标记中options操作方法集合
- js 操作select和option常用代码整理
- JS & JQuery 动态添加 select option
- js select option对象小结
- JS获取select-option-text_value的方法
- javascript对select标签的控制(option选项/select)
- javascript据option的value值快速设定初始的selected选项
- js添加select下默认的option的value和text的方法
- js获取select选中的option的text示例代码
- js获取select默认选中的Option并不是当前选中值
- JS实现select选中option触发事件操作示例
