JS更改select內option屬性的方法,js更改selectoption

來源:互聯網
上載者:User

JS更改select內option屬性的方法,js更改selectoption

本文執行個體講述了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程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.