熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

JS操作select下拉框動態變動

2013-11-15 12:02:53  來源: JSP教程 

  動態創建select

     function createSelect(){

         var mySelect = documentcreateElement_x("select");

         mySelectid = "mySelect";  

         documentbodyappendChild(mySelect);

     }

  添加選項option

    function addOption(){

         //根據id查找對象

          var obj=documentgetElementByIdx_x(mySelect);

          //添加一個選項

          objadd(new    Option("文本""值"));   

    }

  刪除所有選項option

    function removeAll(){

          var obj=documentgetElementByIdx_x(mySelect);

   

          objoptionslength= 

    }

  刪除一個選項option

  function removeOne(){

          var obj=documentgetElementByIdx_x(mySelect);

          //index要刪除選項的序號這裡取當前選中選項的序號

          var index=objselectedIndex;

          objoptionsremove(index);  

    }

  獲得選項option的值

  var obj=documentgetElementByIdx_x(mySelect);

  var index=objselectedIndex; //序號取當前選中選項的序號

  var val = objoptions[index]value;

  獲得選項option的文本

  var obj=documentgetElementByIdx_x(mySelect);

  var index=objselectedIndex; //序號取當前選中選項的序號

  var val = objoptions[index]text;

  修改選項option

  var obj=documentgetElementByIdx_x(mySelect);

  var index=objselectedIndex; //序號取當前選中選項的序號

  var val = objoptions[index]=new Option("新文本""新值");

  刪除select

     function removeSelect(){

           var mySelect = documentgetElementByIdx_x("mySelect");

          mySelectparentNoderemoveChild(mySelect);

    }


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20153.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.