| 作者: | jjdai (jjdai) | | 圖 | | 時間: | 2007-06-26 03:17:47 | | 來源: | 61.230.205.249 |
| | 此文: | | 點閱: | 2060 | | 回覆: | 0 |
| [HTML][JS] 相容於 IE 和 FireFox 的 options.add() 寫法.
var oOption = document.createElement("OPTION");
document.getElementById("IdOfOpt").options.add(oOption);
oOption.Text = "顯示的文字"; // 或用 oOption.innerText = "..."
oOption.Value = "數值";
如果是在「子視窗」想對「父視窗」的 options 元件新增一欄位,則用
var oOption = parent.opener.document.createElement("OPTION");
這篇文章的關鍵字:
IE6, FireFox, document.createElement("OPTION"), select, parent.opener
|