免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
HTML中select標(biāo)簽單選多選詳解

select元素可創(chuàng)建單選或多選菜單。當(dāng)提交表單時,瀏覽器會提交選定的項目,或者收集用逗號分隔的多個選項,將其合成一個單獨的參數(shù)列表,并且在將 <select>表單數(shù)據(jù)提交給服務(wù)器時包括 name屬性。

一、基本用法:

<select>

 <option value ="volvo">Volvo</option>

 <option value ="saab">Saab</option>

 <option value="opel">Opel</option>

 <option value="audi">Audi</option>

</select>

其中,</option>標(biāo)簽可以省掉,在頁面中用法

<SELECTNAME="studyCenter"id="studyCenter" SIZE="1">

          <OPTIONVALUE="0">全部

          <OPTIONVALUE="1">湖北電大網(wǎng)絡(luò)學(xué)習(xí)中心

          <OPTIONVALUE="2">成都師范學(xué)院網(wǎng)絡(luò)學(xué)習(xí)中心

          <OPTIONVALUE="3">武漢職業(yè)技術(shù)學(xué)院網(wǎng)絡(luò)學(xué)習(xí)中心

  </SELECT>

二、Select元素還可以多選,看如下代碼:

//multiple屬性,則可以多選
<select name= “education” id=”education” multiple=”multiple”>
       <option value=”1”>
高中</option>
       <option value=”2”>
大學(xué)</option>
       <option value=”3”>
博士</option>
</select>

//
下面沒有multiple屬性 , 只顯示一條,不能多選
<select name= “education” id=”education” >
       <option value=”1”>
高中</option>
       <option value=”2”>
大學(xué)</option>
       <option value=”3”>
博士</option>
</select>
//
下面是設(shè)置了size屬性的情況 , 如果size = 3那么就顯示三條數(shù)據(jù),注意不能多選的。
<select name="education" id="education" size='3'>
         <option value="0">
小學(xué)</option>
         <option value="1">
初中</option>
         <option value="2">
高中</option>
         <option value="3">
中專</option>
         <option value="4">
大專</option>
         <option value="5">
本科</option>
         <option value="6">
研究生</option>
         <option value="7">
博士</option>
         <option value="8">
博士后</option>
         <option selected>
請選擇</option>
</select>

 

三、 多選Select組件涉及的所有常用操作:

1.     判斷select選項中是否存在指定值的Item 

@param objSelectId將要驗證的目標(biāo)select組件的id

@param objItemValue將要驗證是否存在的值

function isSelectItemExit(objSelectId,objItemValue)  { 
 var objSelect = document.getElementById(objSelectId);
    var isExit = false; 
    if (null != objSelect && typeof(objSelect) != "undefined") {
     for(var i=0;i<objSelect.options.length;i++) { 
         if(objSelect.options[i].value == objItemValue) { 
             isExit = true; 
             break; 
         } 
     } 
    }
    return isExit;
 }

2.     select選項中加入一個Item

@param  objSelectId 將要加入item的目標(biāo)select組件的id
@param objItemText 
將要加入的item顯示的內(nèi)容
@param objItemValue
將要加入的item的值

function addOneItemToSelect(objSelectId,objItemText,objItemValue) { 
 var objSelect = document.getElementById(objSelectId);
    if (null != objSelect && typeof(objSelect) != "undefined") {
      //
判斷是否該值的item已經(jīng)在select中存在
     if(isSelectItemExit(objSelectId,objItemValue)) { 
         $.messager.alert('
提示消息','該值的選項已經(jīng)存在!','info');
     }  else  {
         var varItem = new Option(objItemText,objItemValue); 
         objSelect.options.add(varItem); 
     } 
    }
}

3.   select選項中刪除選中的項,支持多選多刪

@param objSelectId 將要進(jìn)行刪除的目標(biāo)select組件id

function removeSelectItemsFromSelect(objSelectId) { 
 var objSelect = document.getElementById(objSelectId);
 var delNum = 0;
     if (null != objSelect && typeof(objSelect) != "undefined") {
        for(var i=0;i<objSelect.options.length;i=i+1) { 
            if(objSelect.options[i].selected) { 
                objSelect.options.remove(i); 
                delNum = delNum + 1;
                i = i - 1;
            } 
        }        
     if (delNum <= 0 ) {
      $.messager.alert('
提示消息','請選擇你要刪除的選項!','info');
     } else {
      $.messager.alert('
提示消息','成功刪除了'+delNum+'個選項!','info');
     }
     }
}

4.     select選項中按指定的值刪除一個Item  
  @param objSelectId
將要驗證的目標(biāo)select組件的id
  @param objItemValue
將要驗證是否存在的值

function removeItemFromSelectByItemValue(objSelectId,objItemValue) { 
 var objSelect = document.getElementById(objSelectId);
     if (null != objSelect && typeof(objSelect) != "undefined") {
      //
判斷是否存在
       if(isSelectItemExit(objSelect,objItemValue)) { 
         for(var i=0;i<objSelect.options.length;i++) { 
             if(objSelect.options[i].value == objItemValue) { 
                 objSelect.options.remove(i); 
                 break; 
             } 
         }        
         $.messager.alert('
提示消息','成功刪除!','info');            
     } else { 
         $.messager.alert('
提示消息','不存在指定值的選項!','info'); 
     }    
     }
}

5.     清空select中的所有選項

@param objSelectId 將要進(jìn)行清空的目標(biāo)select組件id
function clearSelect(objSelectId) { 
 var objSelect = document.getElementById(objSelectId);
     if (null != objSelect && typeof(objSelect) != "undefined") {
        for(var i=0;i<objSelect.options.length;) { 
          objSelect.options.remove(i); 
        }        
     }
}

6.獲取select中的所有item,并且組裝所有的值為一個字符串,值與值之間用逗號隔開
 @param objSelectId 
目標(biāo)select組件id
 @return select
中所有item的值,值與值之間用逗號隔開

function getAllItemValuesByString(objSelectId) {
 var selectItemsValuesStr = "";
 var objSelect = document.getElementById(objSelectId);
 if (null != objSelect && typeof(objSelect) != "undefined") {
      var length = objSelect.options.length
        for(var i = 0; i < length; i = i + 1) { 
         if (0 == i) {
            selectItemsValuesStr = objSelect.options[i].value;
         } else {
            selectItemsValuesStr = selectItemsValuesStr + "," + objSelect.options[i].value;
         }
        }  
     } 
     return selectItemsValuesStr;
}

7.將一個select中的所有選中的選項移到另一個select中去
  @param fromObjSelectId 
移動item的原select組件id
  @param toObjectSelectId 
移動item將要進(jìn)入的目標(biāo)select組件
id
 function moveAllSelectedToAnotherSelectObject(fromObjSelectId, toObjectSelectId) { 
 var objSelect = document.getElementById(fromObjSelectId);
 var delNum = 0;
     if (null != objSelect && typeof(objSelect) != "undefined") {
        for(var i=0;i<objSelect.options.length;i=i+1) { 
            if(objSelect.options[i].selected) { 
                addOneItemToSelect(toObjectSelectId,objSelect.options[i].text,objSelect.options[i].value)
                objSelect.options.remove(i);
                i = i - 1;
            }
        }        
     }
}

8.將一個select中的所有選項移到另一個select中去
 @param fromObjSelectId 
移動item的原select組件id
 @param toObjectSelectId 
移動item將要進(jìn)入的目標(biāo)select組件
id
 function moveAllToAnotherSelectObject(fromObjSelectId, toObjectSelectId) { 
 var objSelect = document.getElementById(fromObjSelectId);
     if (null != objSelect) {
      for(var i=0;i<objSelect.options.length;i=i+1) { 
             addOneItemToSelect(toObjectSelectId,objSelect.options[i].text,objSelect.options[i].value)
             objSelect.options.remove(i);
             i = i - 1;
        }  
     }
}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
javascript Select標(biāo)記中options操作方法集合
JS操作select相關(guān)方法
javascript對select的操作
easyui獲得datagrid總行數(shù)
jQuery EasyUI Tabs關(guān)閉Tab時不能完全釋放內(nèi)存解決方法
javascript操作Select中的 options集合
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服