[HTML][JS] 相容於 IE 和 FireFox 的 options.add() 寫法

[HTML][JS] 相容於 IE 和 FireFox 的 options.add() 寫法.

var oOption = document.createElement(“OPTION”);
document.getElementById(“IdOfOpt”).options.add(oOption);
oOption.Text = “顯示的文字”; // 或用 oOption.innerText = “…”
oOption.Value = “數值”;

如果是在「子視窗」想對「父視窗」的 options 元件新增一欄位,則用以下程式取得 oOption:

var oOption = parent.opener.document.createElement(“OPTION”);


這篇文章的關鍵字:

IE6, FireFox, document.createElement(“OPTION”), select, parent.opener

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.