<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        js下拉菜單生成器dropMenu使用方法詳解

        來源:懂視網 責編:小OO 時間:2020-11-27 22:33:36
        文檔

        js下拉菜單生成器dropMenu使用方法詳解

        本文實例為大家分享了下拉菜單生成器dropMenu的使用方法,供大家參考,具體內容如。HTML;<;div class="input-group">;  <;span class="input-group-addon" style="width: 100px" >;職級:<;/span>;<;input type="text" class="units form-control" id="jobTitle" value="其他" style="border-radius:0 4px 4px 0;">;<;/input>;<;span class="caret beside">;<;/span>;<;/div>。js;
        推薦度:
        導讀本文實例為大家分享了下拉菜單生成器dropMenu的使用方法,供大家參考,具體內容如。HTML;<;div class="input-group">;  <;span class="input-group-addon" style="width: 100px" >;職級:<;/span>;<;input type="text" class="units form-control" id="jobTitle" value="其他" style="border-radius:0 4px 4px 0;">;<;/input>;<;span class="caret beside">;<;/span>;<;/div>。js;

        本文實例為大家分享了下拉菜單生成器dropMenu的使用方法,供大家參考,具體內容如

        HTML

        <div class="input-group">
           <span class="input-group-addon" style="width: 100px" >職級:</span>
         <input type="text" class="units form-control" id="jobTitle" value="其他" style="border-radius:0 4px 4px 0;"></input>
         <span class="caret beside"></span>
        </div>
        

        js

        $(function(){
         var title,
         populationType,
         titleInParty;
         $.ajax({
         url:'/api/v1/user/getUserTypeInfo',
         type:'GET',
         dataType:'json',
         success:function (data) {
         title=data.data.title;
         titleInParty=data.data.titleInParty;
         populationType=data.data.populationType;
         partyLabel('jobTitle',title);
         partyLabel('populationType',populationType);
         partyLabel('titleInParty',titleInParty);
         }
         });
        
        function partyLabel(menuID,data){
         new DropMeun({
         'id':menuID,
         "data":data,
         "dataSrc":"name", //數據是下面的這種格式的,你要的是name的值
         "ableSearch":true, //可以搜索
         "style":{ //樣式,可選
         "width":173,
         "maxHeight":200,
         "left":0, //定位到哪里
         "top":5,
         "initPos":"left" //設置在哪邊出現
         }
         })
         }
        

        3.在頁面中引用一個js 文件

        (function(vq0599) {
         window.DropMeun = vq0599
        })(function() {
        
         /*-- tools --*/
        
         function getRealTop(node) {
         return node.offsetParent.tagName.toUpperCase() === 'BODY' ?
         node.offsetTop :
         node.offsetTop + arguments.callee(node.offsetParent)
         }
        
         function getRealLeft(node) {
         return node.offsetParent.tagName.toUpperCase() === 'BODY' ?
         node.offsetLeft :
         node.offsetLeft + arguments.callee(node.offsetParent)
         }
        
         /*-- tools end--*/
        
        
         function DropMeun(option) {
         this.picker = null
         this.self = null
         this.option = option
         this.item = option.item || []
         this.style = option.style || {}
         this.dataList = option.data || []
        
         this.init()
         return this;
         }
        
         DropMeun.prototype.init = function () {
         var html = '',
         _this = this
        
         this.self = document.createElement('ul')
         this.picker = document.getElementById(this.option.id)
        
         if (! this.picker) {
         throw 'picker is null, making sure that picker\'s ID \''+ this.option.id +'\' is correct'
         return
         }
        
        
         if (this.option.ableSearch) {
         html += '<li><input class="dropMeun-searchInput" type="text"></li>'
         }
        
         this.dataList.forEach(function(data, index) {
         var item = _this.option.dataSrc ? data[_this.option.dataSrc] : data,
         content = _this.item.render ? _this.item.render(item, data) : item
        
         html += '<li class="dropMeun-item '+ (_this.item.className || '') +'" data-index="'+ index +'">'+ content +'</li>'
         })
        
         this.self.classList.add('dropMeun')
         this.self.innerHTML = html
         document.body.appendChild(this.self)
        
         this.setStyle()
         this.bindEvent()
         }
        
         DropMeun.prototype.setStyle = function() {
        
         this.self.style.width =
         this.style.width ?
         (parseInt(this.style.width) - 26) + 'px' :
         '150px'
        
         this.self.style.maxHeight =
         this.style.maxHeight ?
         (parseInt(this.style.maxHeight) - 26) + 'px' :
         '300px'
        
         var w = getRealLeft(this.picker) + (parseInt(this.style.left) || 0)
         var h = getRealTop(this.picker) + this.picker.offsetHeight + (parseInt(this.style.top) || 0)
        
         var realWidth = parseInt(this.self.style.width) + 26 // 26 = dobule(padding + border)
        
         if (this.style.initPos === 'right') {
         w = w - realWidth + this.picker.offsetWidth
         }
        
         this.self.style.top = h + 'px'
         this.self.style.left = w + 'px'
        
         }
        
         DropMeun.prototype.bindEvent = function() {
         var
        
         _this = this,
         iEvent = this.picker.nodeName.toUpperCase() !== 'INPUT' ?
         'click' :
         this.picker.type.toUpperCase() === 'TEXT' ?
         'focus' : 'click'
        
         this.picker.addEventListener('click', function(ev) {
         var ev = ev || window.ev
         ev.stopPropagation()
         })
        
         //
         this.picker.addEventListener(iEvent, function(ev) {
        
         document.body.click() // 觸發 window.click 使其他dropMeun關閉
        
         _this.self.style.display = 'block'
         })
        
         //
         window.addEventListener('click', function() {
         _this.self.style.display = 'none'
         })
        
         //
         this.self.addEventListener('click', function(ev) {
         var ev = ev || window.ev
         ev.stopPropagation()
        
         // 事件委托 item點擊
         if (ev.target.classList.contains('dropMeun-item')) {
         var index = parseInt(ev.target.getAttribute('data-index'))
         data = _this.option.dataSrc ?
         _this.dataList[index][_this.option.dataSrc] :
         _this.dataList[index]
        
        
         if (iEvent === 'focus') {
         _this.picker.value = ev.target.innerText
         }
        
         if (_this.item.callbakc) {
         _this.item.callbakc(data, _this.picker, _this.dataList[index], _this.dataList)
         }
        
         _this.self.style.display = 'none'
         }
         })
         //
         if (_this.option.ableSearch) {
        
         _this.searchInput = _this.self.getElementsByClassName('dropMeun-searchInput')[0]
        
         _this.searchInput.addEventListener('keyup', function() {
         var target = this.value.trim(),
         items = _this.self.getElementsByClassName('dropMeun-item');
        
         [].slice.call(items).forEach(function(item, index) {
         item.style.display =
         item.innerText.indexOf(target) === -1 ?
         'none' : ''
         })
        
         })
         }
         }
        
         return DropMeun
        }())
        

        4.在頁面中引用一個css文件

        ul,
        li {
         list-style: none;
         margin: 0;
         padding: 0;
        }
        
        .dropMeun {
         position: absolute;
         border: 1px solid #ccc;
         overflow: auto;
         padding: 8px 12px;
         box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
         background-color: #fff;
         border-bottom-left-radius: 4px;
         border-bottom-right-radius: 4px;
         box-sizing: content-box;
         display: none;
        }
        
        .dropMeun li.dropMeun-item {
         min-width: 150px;
         padding: 2px 2px;
         white-space: nowrap;
         overflow: hidden;
         text-overflow: ellipsis;
        }
        
        .dropMeun li.dropMeun-item:hover {
         cursor: pointer;
         background-color: rgba(238, 238, 238, 0.8);
        }
        
        .dropMeun-searchInput {
         outline: none;
         width: 100%;
         box-sizing: border-box;
        }
        

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        js下拉菜單生成器dropMenu使用方法詳解

        本文實例為大家分享了下拉菜單生成器dropMenu的使用方法,供大家參考,具體內容如。HTML;<;div class="input-group">;  <;span class="input-group-addon" style="width: 100px" >;職級:<;/span>;<;input type="text" class="units form-control" id="jobTitle" value="其他" style="border-radius:0 4px 4px 0;">;<;/input>;<;span class="caret beside">;<;/span>;<;/div>。js;
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 91情侣在线精品国产免费| 免费观看成人久久网免费观看| 青草草色A免费观看在线| 午夜影视日本亚洲欧洲精品一区| 国产免费观看a大片的网站| 亚洲综合精品香蕉久久网| 色偷偷亚洲女人天堂观看欧| 91嫩草免费国产永久入口| 亚洲午夜久久久久久久久久| 久久久久久噜噜精品免费直播 | 色窝窝免费一区二区三区| 亚洲香蕉在线观看| 韩国欧洲一级毛片免费| 朝桐光亚洲专区在线中文字幕| 亚洲第一页综合图片自拍| 免费一级毛片在线播放视频| 中文字幕亚洲免费无线观看日本| 1000部拍拍拍18勿入免费视频软件 | 全部免费a级毛片| 三级毛片在线免费观看| 亚洲AV综合色区无码一区 | 一级特黄色毛片免费看| 区久久AAA片69亚洲| 午夜爽爽爽男女免费观看影院| 91亚洲国产成人久久精品网址| 97国免费在线视频| 亚洲高清在线mv| 国产成人免费片在线观看| 久草免费福利在线| 亚洲永久中文字幕在线| 国产精品免费看久久久无码| 免费网站观看WWW在线观看| 亚洲人成在线中文字幕| 亚洲?V乱码久久精品蜜桃| 亚洲人成色在线观看| 久久精品国产亚洲AV不卡| 免费v片在线观看视频网站| 粉色视频在线观看www免费| 黑人精品videos亚洲人| 国产永久免费高清在线| 亚洲嫩草影院在线观看|