JS更改select內(nèi)option屬性的方法
本文實(shí)例講述了JS更改select內(nèi)option屬性的方法。分享給大家供大家參考。具體如下:
幫一位友人解決了一個(gè)小問題,需求是更改選中選項(xiàng)卡內(nèi)顯示的文本值,新值存放在某個(gè)文本框內(nèi)
初始窗口:
<html> <head> <title>原窗口</title> <script> var parentValue=""; //全局變量,用于保存點(diǎn)擊詳情時(shí)select中指定opeion的值 function detail() { var select=document.getElementById('SHGX'); //獲得select對(duì)象 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='獨(dú)生子'>獨(dú)生子</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>
希望本文所述對(duì)大家的JavaScript程序設(shè)計(jì)有所幫助。
- javascript Select標(biāo)記中options操作方法集合
- js 操作select和option常用代碼整理
- JS & JQuery 動(dòng)態(tài)添加 select option
- js select option對(duì)象小結(jié)
- JS獲取select-option-text_value的方法
- javascript對(duì)select標(biāo)簽的控制(option選項(xiàng)/select)
- javascript據(jù)option的value值快速設(shè)定初始的selected選項(xiàng)
- js添加select下默認(rèn)的option的value和text的方法
- js獲取select選中的option的text示例代碼
- js獲取select默認(rèn)選中的Option并不是當(dāng)前選中值
- JS實(shí)現(xiàn)select選中option觸發(fā)事件操作示例
相關(guān)文章

bootstrap datetimepicker2.3.11時(shí)間插件使用

JS在IE和FF下attachEvent,addEventListener學(xué)習(xí)筆記

webpack4 升級(jí)遷移的實(shí)現(xiàn)

layui多iframe頁(yè)面控制定時(shí)器運(yùn)行的方法

JS 添加網(wǎng)頁(yè)桌面快捷方式的代碼詳細(xì)整理

xmlplus組件設(shè)計(jì)系列之圖標(biāo)(ICON)(1)