風人園

          弱水三千,只取一瓢,便能解渴;佛法無邊,奉行一法,便能得益。
          隨筆 - 99, 文章 - 181, 評論 - 56, 引用 - 0
          數據加載中……

          用javascript操作select

          ?1 1 ?檢測是否有選中
          ?2 if (objSelect.selectedIndex? > ? - 1 )? {
          ?3 // 說明選中
          ?4 }
          ? else ? {
          ?5 // 說明沒有選中
          ?6 }

          ?7
          ?8 2 ?刪除被選中的項?
          ?9 objSelect.options[objSelect.selectedIndex]? = ? null ;
          10
          11 3 ?增加項
          12 objSelect.options[objSelect.length]? = ? new ?Option( " 你好 " , " hello " );
          13
          14 4 ?修改所選擇中的項
          15 objSelect.options[objSelect.selectedIndex]? = ? new ?Option( " 你好 " , " hello " );
          16
          17 5 ?得到所選擇項的文本
          18 objSelect.options[objSelect.selectedIndex].text;
          19
          20 6 ?得到所選擇項的值
          21 objSelect.options[objSelect.selectedIndex].value;

          < form???name = " test " > ???
          ??
          < select???name = " obj " ></ select > ???
          ??
          < input???type = " button " ???onclick = " javascript:itemDelete(document.test.obj); " > ???
          ??
          </ form > ???
          ??
          // delete???
          ?? function ???itemDelete(obj) {???
          ??
          var ???lengthObj??? = ???obj.length;???
          ??
          for (i??? = ??? 0 ;i??? < ???lengthObj;i ++ ) {???
          ??
          if (obj.options[i].selected) {???
          ??obj.remove(i);???
          ??lengthObj???
          = ???obj.length;???
          ??i
          -- ;???
          ??}
          ???
          ??}
          ???
          ??}

          function ???delOption() {???
          ??????
          var ???obj??? = ???document.myForm.aa;???
          ??????
          var ???opts = ???obj.options;???
          ??????
          var ???index??? = ??? 1 ;???
          ??????opts[index]???
          = ??? null ;???
          ??}
          ???
          ??
          function ???addOption() {???
          ??????
          var ???obj??? = ???document.myForm.aa;???
          ??????
          var ???opts = ???obj.options;???
          ??????
          var ???opt??? = ??? new ???Option( " " , " " );???
          ??????opts.length
          ++ ;???
          ??????opts[opts.length
          - 1 ]??? = ???opt;???
          ??}
          ???

          posted on 2007-03-05 08:30 風人園 閱讀(392) 評論(0)  編輯  收藏 所屬分類: JavaScript

          主站蜘蛛池模板: 祁门县| 化德县| 舞阳县| 大关县| 孟村| 增城市| 沛县| 江安县| 河北区| 类乌齐县| 孙吴县| 玉溪市| 澄城县| 岢岚县| 邳州市| 丹阳市| 瑞金市| 巴彦县| 盖州市| 乐亭县| 庆阳市| 达州市| 胶南市| 涞水县| 德庆县| 咸宁市| 巢湖市| 广西| 上蔡县| 辽阳市| 翁源县| 延庆县| 无棣县| 玛纳斯县| 吉林省| 遂川县| 古丈县| 朝阳区| 原平市| 长宁区| 武平县|