亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

js select option對象小結

 更新時間:2013年12月20日 09:32:45   作者:  
本篇文章主要是對js中的select option對象進行了總結介紹,需要的朋友可以過來參考下,希望對大家有所幫助

一基礎理解:

var e = document.getElementById("selectId");

e. options= new Option("文本","值") ;

//創(chuàng)建一個option對象,即在<select>標簽中創(chuàng)建一個或多個<option value="值">文本</option>

//options是個數(shù)組,里面可以存放多個<option value="值">文本</option>這樣的標簽

1:options[ ]數(shù)組的屬性:

length屬性---------長度屬性

selectedIndex屬性--------當前被選中的框中的文本的索引值,此索引值是內存自動分配的(0,1,2,3.....)對應(第一個文本值,第二個文本值,第三個文本值,第四個文本值..........)

2:單個option的屬性(---obj.options[obj.selecedIndex]是指定的某個<option>標簽,是一個---)

text屬性---------返回/指定 文本

value屬性------返回/指定 值,與<options value="...">一致。

index屬性-------返回下標,

selected 屬性-------返回/指定該對象是否被選中.通過指定 true 或者 false,可以動態(tài)的改變選中項

defaultSelected 屬性-----返回該對象默認是否被選中。true / false。

3:option的方法

增加一個<option>標簽-----obj.options.add(new("文本","值"));<增>

刪除一個<option>標簽-----obj.options.remove(obj.selectedIndex)<刪>

獲得一個<option>標簽的文本-----obj.options[obj.selectedIndex].text<查>

修改一個<option>標簽的值-----obj.options[obj.selectedIndex]=new Option("新文本","新值")<改>

刪除所有<option>標簽-----obj.options.length = 0

獲得一個<option>標簽的值-----obj.options[obj.selectedIndex].value

注意:

a:上面的寫的是如這樣類型的方法obj.options.function()而不寫obj.funciton,是因為為了考慮在IE和FF 下的兼容,如obj.add()只能在IE中有效.

b:obj.option中的option不需要大寫,new Option中的Option需要大寫

二 應用

復制代碼 代碼如下:

<html>
<head>
<script language="javascript">
function number(){
var obj = document.getElementById("mySelect");
    //obj.options[obj.selectedIndex] = new Option("我的吃吃","4");//在當前選中的那個的值中改變
    //obj.options.add(new Option("我的吃吃","4"));再添加一個option
    //alert(obj.selectedIndex);//顯示序號,option自己設置的
    //obj.options[obj.selectedIndex].text = "我的吃吃";更改值
   //obj.remove(obj.selectedIndex);刪除功能
}
</script>
</head>
<body>
<select id="mySelect">
     <option>我的包包</option>
     <option>我的本本</option>
     <option>我的油油</option>
     <option>我的擔子</option>
</select>
<input type="button" name="button" value="查看結果" onclick="number();">
</body>
</html>

根據(jù)這些東西,自己用JQEURY AJAX+JSON實現(xiàn)了一個小功能如下:

JS代碼:(只取了于SELECT相關的代碼)

復制代碼 代碼如下:

/**
   * @description  構件聯(lián)動下拉列表 (用JQUERY 的AJAX配合JSON實現(xiàn))
   * @prarm  selectId 下拉列表的ID
   * @prarm  method  要調用的方法名稱
   * @prarm  temp 此處存放軟件ID
   * @prarm  url  要跳轉的地址
   */
function  linkAgeJson(selectId,method,temp,url){   
      $j.ajax({    
            type: "get",//使用get方法訪問后臺
            dataType: "json",//返回json格式的數(shù)據(jù)
            url: url,//要訪問的后臺地址
            data: "method=" + method+"&temp="+temp,//要發(fā)送的數(shù)據(jù)        
            success: function(msg){//msg為返回的數(shù)據(jù),在這里做數(shù)據(jù)綁定
                var data = msg.lists;
                coverJsonToHtml(selectId,data);             
            }
        });
}

/**
* @description  將JSON數(shù)據(jù)轉換成HTML數(shù)據(jù)格式
* @prarm selectId 下拉列表的ID
* @prarm  nodeArray 返回的JSON數(shù)組
*
*/
function coverJsonToHtml(selectId,nodeArray){
//get select
   var tempSelect=$j("#"+selectId);
   //clear select value
   isClearSelect(selectId,'0');   
var tempOption=null;
for(var i=0;i<nodeArray.length;i++){
//create select Option
tempOption= $j('<option value="'+nodeArray[i].dm+'">'+nodeArray[i].mc+'</option> ');
//put Option to select
tempSelect.append(tempOption);
        }
        // 獲取退化構件列表
       getCpgjThgl(selectId,'thgjDm');
   }
   /**
   * @description  清空下拉列表的值
   * @prarm selectId 下拉列表的ID
   * @prarm index 開始清空的下標位置
   */
  function isClearSelect(selectId,index){
     var length=document.getElementById(selectId).options.length;
while(length!=index){
      //長度是在變化的,因為必須重新獲取 
          length=document.getElementById(selectId).options.length;
          for(var i=index;i<length;i++)
             document.getElementById(selectId).options.remove(i);
         length=length/2;
     }
   }

/**
* @description 獲取退化構件列表
* @prarm  selectId1 引用軟件下拉列表的ID
* @prarm  selectId2 退化構件下拉列表的ID
*/
   function getCpgjThgl(selectId1,selectId2){
   var obj1=document.getElementById(selectId1);//引用軟件下拉列表
   var obj2=document.getElementById(selectId2);//退化構件下拉列表
   var len=obj1.options.length;
  //當引用軟件列表長度等于1時返回,不做操作
   if(len==1){
          return false;
   }
   //清空下拉列表的值,兩種方式都可以
  // isClearSelect(selectId2,'1'); 
            document.getElementById(selectId2).length=1;
   for(var i=0;i<len; i++){
var option= obj1.options[i]; 
//引用軟件被選中項不加入
if(i!=obj1.selectedIndex){
//克隆OPTION并添加到SELECT中  
obj2.appendChild(option.cloneNode(true));

}

   } 


HTML代碼:
復制代碼 代碼如下:

<TABLE width="100%" border=0 align="left" cellPadding=0 cellSpacing=1>
  <tr>
<td  class="Search_item_18">  <span class="Edit_mustinput">*</span>引用軟件:</td>
<td  class="Search_content_82">
<input name="yyrjMc" id="yyrjMc" type="text" class="Search_input" tabindex="3"  size="30" >
<input name="yyrjDm" id="yyrjDm" type="hidden" >
<input type="button" class="Search_button_select"
onClick="linkAgeTree('linkage','yyrjtree','yyrjMc','yyrjDm','linkageTree','1');" value="選擇...">
</td>
  </tr>
  <tr>
<td class="Search_item"> <span class="Edit_mustinput">*</span>引用分版:</td>
<td  class="Search_content" id="yyfb">
  <select name="yyfbDm" style="width:160" id="yyfbDm" onChange="getCpgjThgl('yyfbDm','thgjDm')">

  </select>
</td>
  </tr>
  <tr>
<td class="Search_item">退化構件:</td>
<td  class="Search_content" id="thgj">
   <select name="thgjDm" style="width:160" id="thgjDm">
<option value="-1" selected>無</option>
   </select>
</td>
  </tr>
</TABLE>

相關文章

  • ES6中export?default和export之間的區(qū)別詳解

    ES6中export?default和export之間的區(qū)別詳解

    export和export?default都是es6語法中用來導出組件的,可以導出的文檔類型有(?數(shù)據(jù)、常量、函數(shù)、js文件、模塊等),下面這篇文章主要給大家介紹了關于ES6中export?default和export之間的區(qū)別的相關資料,需要的朋友可以參考下
    2023-04-04
  • 微信小程序虛擬列表的實現(xiàn)示例

    微信小程序虛擬列表的實現(xiàn)示例

    大部分小程序都會有這樣的需求,頁面有長列表,需要下拉到底時請求后臺數(shù)據(jù),一直渲染數(shù)據(jù),當數(shù)據(jù)列表長時,會發(fā)現(xiàn)明顯的卡頓,頁面白屏閃頓現(xiàn)象,那么如何實現(xiàn)小程序虛擬列表,感興趣的可以了解一下
    2021-07-07
  • javascript實現(xiàn)當前頁導航激活的方法

    javascript實現(xiàn)當前頁導航激活的方法

    這篇文章主要介紹了javascript實現(xiàn)當前頁導航激活的方法,涉及javascript操作css的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-02-02
  • D3.js實現(xiàn)雷達圖的方法詳解

    D3.js實現(xiàn)雷達圖的方法詳解

    大家應該都知道基本圖表一共有六種,分別是柱狀圖、折線圖、散點圖、氣泡圖、餅圖和雷達圖。前面五種圖形都已經介紹過如何實現(xiàn)了,今天我們一起來看看最后的雷達圖。有需要的朋友們可以參考學習下。
    2016-09-09
  • 再談IE中Flash控件的自動激活 ObjectWrap

    再談IE中Flash控件的自動激活 ObjectWrap

    再談IE中Flash控件的自動激活 ObjectWrap...
    2007-03-03
  • js實現(xiàn)動態(tài)改變字體大小代碼

    js實現(xiàn)動態(tài)改變字體大小代碼

    本文為大家介紹下使用js如何實現(xiàn)動態(tài)改變字體大小,感興趣的額朋友不要錯過
    2014-01-01
  • 詳解JavaScript之Array.reduce源碼解讀

    詳解JavaScript之Array.reduce源碼解讀

    這篇文章主要介紹了詳解JavaScript之Array.reduce源碼解讀,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • layui 上傳文件_批量導入數(shù)據(jù)UI的方法

    layui 上傳文件_批量導入數(shù)據(jù)UI的方法

    今天小編就為大家分享一篇layui 上傳文件_批量導入數(shù)據(jù)UI的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-09-09
  • 工作中常用的js、jquery自定義擴展函數(shù)代碼片段匯總

    工作中常用的js、jquery自定義擴展函數(shù)代碼片段匯總

    本文主要對工作中常用的js、jquery自定義擴展函數(shù)代碼片段進行了分享,具有很好的參考價值,需要的朋友一起來看下吧
    2016-12-12
  • 詳解JavaScript跨域總結與解決辦法

    詳解JavaScript跨域總結與解決辦法

    本篇文章主要介紹了JavaScript跨域,詳細的總結了什么是跨域,并介紹了幾種解決辦法,感興趣的小伙伴們可以參考一下。
    2016-10-10

最新評論