自知其無知
          不懂,慢慢懂。
          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 閱讀(720) 評論(0)  編輯  收藏 所屬分類: Java Web
          主站蜘蛛池模板: 越西县| 克东县| 乌兰县| 望都县| 张家港市| 上高县| 文化| 德保县| 松原市| 牟定县| 佛教| 遂昌县| 达孜县| 海盐县| 瓮安县| 买车| 溆浦县| 蒙自县| 灵石县| 密山市| 曲沃县| 滦平县| 抚州市| 广德县| 霞浦县| 沈阳市| 古交市| 灌南县| 广西| 当雄县| 巨野县| 普兰店市| 贵南县| 灵台县| 宁远县| 连山| 郯城县| 镶黄旗| 渑池县| 门源| 浙江省|