自知其無知
          不懂,慢慢懂。
          posts - 2,comments - 2,trackbacks - 0

          轉自: http://www.webdeveloper.com/forum/archive/index.php/t-70927.html

          可謂超級經典:

          whitedog
          06-27-2005, 11:20 AM
          Hi Folks,
          really think that this is a FAQ but cant find
          any docs about this....

          How can i populate a select with optgroups
          is there any standard constructor like
          new Option(text,val,..) which can do???

          OK, i could produce the complete HTML
          -option stuff dynamically onLoad as text and
          via document.write() but i need
          to change later on, so this is a nice twaek
          but wont help me with this....

          BTW, is the any actual documentation about
          this topic? develeoper.netscape.com seemed
          to have closed down, and most other stuff is
          pretty outdated...

          REGARDS!

          whitedog

           

          whitedog
          06-28-2005, 07:59 AM
          Hey Folks, wazzup?

          Anyone any ideas?
          Nor have this ever seen in some documentation
          and let me know where to find??

          Hey Guru's, HELP please!!

           

          Orc Scorcher
          06-28-2005, 08:24 AM
          Well, the problem is that theoretically this is dead simple but in reality IE screws up. Here's an example that works fine in better browsers but the options are invisible in IE6: <select id="theSelect"></select>
          <script>

          void function() {

          var select = document.getElementById("theSelect")
          /* Try again if the DOM tree isn't ready yet */
          if (!select) setTimeout(arguments.callee, 20)

          /* Create the optgroup, it's label and two options
          * then add it to the select */
          var optG = document.createElement("optgroup")
          optG.label = "First Optgroup"
          optG.appendChild(new Option("Option 1"))
          optG.appendChild(new Option("Option 2"))
          select.appendChild(optG)

          optG = document.createElement("optgroup")
          optG.label = "Second Optgroup"
          optG.appendChild(new Option("Option 3"))
          optG.appendChild(new Option("Option 4"))
          select.appendChild(optG)

          }()

          </script>

           

          BigMoosie
          06-28-2005, 08:26 AM
          <FORM name="myForm">
          <SELECT name="mySelect">
          </SELECT>
          </FORM>
          <SCRIPT type="text/javascript">
          var subject=document.createElement("OPTGROUP")
          subject.setAttribute("label", "hello");
          document.forms.myForm.mySelect.appendChild(subject);
          </SCRIPT>

           

          Fang
          06-28-2005, 08:42 AM
          x-browser:var optG = document.createElement("optgroup")
          optG.label = "First Optgroup"
          select.appendChild(optG)
          var oOption = document.createElement("option");
          var txt = document.createTextNode("Option 1");
          oOption.appendChild(txt);
          optG.appendChild(oOption);
          select.appendChild(optG)

          or

          var optG = document.createElement("optgroup")
          optG.label = "First Optgroup"
          select.appendChild(optG)
          select.options[select.options.length] = new Option("Option 1");



           

          posted on 2008-12-15 22:51 CopyHoo 閱讀(719) 評論(0)  編輯  收藏 所屬分類: Java Web
          主站蜘蛛池模板: 渭南市| 新兴县| 闸北区| 买车| 博罗县| 田东县| 邵东县| 洛宁县| 桑日县| 濮阳县| 垫江县| 伊吾县| 巴东县| 桂平市| 昌宁县| 伊春市| 高碑店市| 永吉县| 望奎县| 阿巴嘎旗| 岫岩| 阿城市| 乌鲁木齐市| 驻马店市| 长岛县| 栖霞市| 东丰县| 礼泉县| 武隆县| 大丰市| 宣化县| 汤阴县| 镇原县| 兴国县| 静海县| 苏州市| 安庆市| 龙南县| 福安市| 贞丰县| 洱源县|