成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

基于jquery實現(xiàn)多選下拉列表

本文實例為大家分享了jquery實現(xiàn)多選下拉列表展示的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)公司專注于燈塔網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供燈塔營銷型網(wǎng)站建設(shè),燈塔網(wǎng)站制作、燈塔網(wǎng)頁設(shè)計、燈塔網(wǎng)站官網(wǎng)定制、重慶小程序開發(fā)服務(wù),打造燈塔網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供燈塔網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
   ul li{
    list-style: none;
    }
   .hide{display: none}
   .width250{
    width: 150px;
    }
   .width250 input[type="text"]{
     width: 100%; 
     height: 32px; 
     border: 1px solid #ccc; 
     border-radius: 4px; 
     padding-left: 12px;
   }
    .width250 ul{ 
      width: 96%; 
      padding: 0 0 0 20px; 
      margin: 0; 
      border: 1px solid #ccc; 
    }
    .width250 li{ 
      padding: 5px; 
    }
    .width250 li+li{ 
      border-top: 1px solid #ccc; 
    }
  </style>
</head>
<body> 
  <form id="form">  
    <div class="width250">
      可多選年份:<input type="text" id="yearInput" placeholder="請選擇年份" readonly>
      <ul id="yearId" class="hide">
      </ul>
    </div>
  </form>
</body>
<script type="text/javascript" src="jquery.js"></script>
<script>
  (function(){
    var str = '';
    var arr = {
      0 : {name:'2015',id:0},
      1 : {name:'2016',id:0},
      2 : {name:'2017',id:0}
    };
    for (let x in arr){
      console.info(x);
      str += `<li><label><input type="checkbox" value="${arr[x].id}" data-name="${arr[x].name}">${arr[x].name}</label></li>`;
    }
    $('#yearId').html(str);
  })();

  $("#yearInput").click(function(){
    $(this).attr('placeholder','');
    var name = '';
    $('#yearId input').each(function () {//循環(huán)遍歷checkbox
      var check=$(this).is(':checked');//判斷是否選中
      if(check){
        name += $(this).attr('data-name')+',';
        $(this).attr('name',"yearId");
      }else {
        $(this).attr('name',"");
      }
    });
    $("#yearInput").val(name.slice(0,-1));//去除最后的逗號
  });

  $("#yearId").mouseover(function() {
    if (!$("#yearId").hasClass('hover')){//類hover在下面用來驗證是否需要隱藏下拉,沒有其他用途。
      $("#yearId").addClass('hover');
    }
  }).mouseout(function(){
    $("#yearId").removeClass('hover');
  });

  $(document).on('click',function() {
    if (!$("#yearInput").is(":focus") && !$("#yearId").hasClass('hover')) {//如果沒有選中輸入框且下拉不在hover狀態(tài)。
      var name = '';
      $('#yearId input').each(function () {//遍歷checkbox
        var check = $(this).is(':checked');//判斷是否選中
        if (check) {
          name += $(this).attr('data-name') + ',';
          $(this).attr('name', "yearId");
        } else {
          $(this).attr('name', "");
        }
      });
      $("#yearInput").val(name.slice(0, -1));//去除最后的逗號
      $("#yearId").addClass('hide');
    } else {
      $("#yearId").removeClass('hide');
    }
  });
</script>
</html>

效果圖:

基于jquery實現(xiàn)多選下拉列表

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

文章名稱:基于jquery實現(xiàn)多選下拉列表
轉(zhuǎn)載注明:http://jinyejixie.com/article32/gpeppc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)ChatGPT、網(wǎng)站制作、品牌網(wǎng)站建設(shè)、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
湄潭县| 松桃| 昌图县| 光山县| 凉城县| 焦作市| 天水市| 佳木斯市| 九龙县| 区。| 哈密市| 平顶山市| 通许县| 吉木萨尔县| 鞍山市| 纳雍县| 满城县| 济源市| 清徐县| 炎陵县| 贵定县| 五台县| 奉贤区| 衡阳市| 丘北县| 略阳县| 司法| 丰台区| 南通市| 塔河县| 商丘市| 楚雄市| 防城港市| 汉阴县| 渭南市| 盐池县| 永川市| 织金县| 平舆县| 沂源县| 北京市|