茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    HTML中select標(biāo)簽單選多選用法詳解
    來源:易賢網(wǎng) 閱讀:1024 次 日期:2014-10-10 13:54:40
    溫馨提示:易賢網(wǎng)小編為您整理了“HTML中select標(biāo)簽單選多選用法詳解”,方便廣大網(wǎng)友查閱!

    select 元素可創(chuàng)建單選或多選菜單。當(dāng)提交表單時,瀏覽器會提交選定的項目,或者收集用逗號分隔的多個選項,將其合成一個單獨(dú)的參數(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)簽可以省掉,在頁面中用法

    代碼如下:

    <SELECT NAME="studyCenter" id="studyCenter" SIZE="1">

    <OPTION VALUE="0">全部

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

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

    <OPTION VALUE="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;

    }

    }

    }

    更多信息請查看IT技術(shù)專欄

    更多信息請查看網(wǎng)頁制作
    易賢網(wǎng)手機(jī)網(wǎng)站地址:HTML中select標(biāo)簽單選多選用法詳解
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機(jī)號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)