JS更改select內(nèi)option屬性的方法
更新時間:2015年10月14日 11:05:28 作者:w93223010
這篇文章主要介紹了JS更改select內(nèi)option屬性的方法,涉及JavaScript動態(tài)操作頁面select元素屬性的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了JS更改select內(nèi)option屬性的方法。分享給大家供大家參考。具體如下:
幫一位友人解決了一個小問題,需求是更改選中選項卡內(nèi)顯示的文本值,新值存放在某個文本框內(nèi)
初始窗口:
<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); //調(diào)用父窗口的函數(shù)
}
</script>
</head>
<body>
<input id="text_01" type="text" value=""/>
<button onclick="modify();">修改</button>
</body>
</html>
希望本文所述對大家的JavaScript程序設(shè)計有所幫助。
您可能感興趣的文章:
- javascript Select標(biāo)記中options操作方法集合
- js 操作select和option常用代碼整理
- JS & JQuery 動態(tài)添加 select option
- js select option對象小結(jié)
- JS獲取select-option-text_value的方法
- javascript對select標(biāo)簽的控制(option選項/select)
- javascript據(jù)option的value值快速設(shè)定初始的selected選項
- js添加select下默認(rèn)的option的value和text的方法
- js獲取select選中的option的text示例代碼
- js獲取select默認(rèn)選中的Option并不是當(dāng)前選中值
- JS實現(xiàn)select選中option觸發(fā)事件操作示例
相關(guān)文章
bootstrap datetimepicker2.3.11時間插件使用
這篇文章主要為大家詳細(xì)介紹了bootstrap datetimepicker2.3.11時間插件使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
2016-11-11
JS在IE和FF下attachEvent,addEventListener學(xué)習(xí)筆記
今天小弄了一下JS事件,主要說一下FF和IE兼容的問題
2009-11-11
JS 添加網(wǎng)頁桌面快捷方式的代碼詳細(xì)整理
如何添加桌面快捷?很多網(wǎng)友都有這個疑問;JS 點擊添加網(wǎng)頁桌面快捷方式的代碼,需要的朋友可以參考下
2012-12-12
xmlplus組件設(shè)計系列之圖標(biāo)(ICON)(1)
這篇文章主要為大家詳細(xì)介紹了xmlplus組件設(shè)計系列之圖標(biāo)ICON的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
2017-05-05 
