国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答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
主站蜘蛛池模板: 国产精品一区二区国产 | 亚洲国产精品二区久久 | 好骚综合在线 | 亚洲综合一区二区三区 | 国产精品亚洲色图 | 精品国产日韩亚洲一区二区 | 香港经典a毛片免费观看…伊人色综合久久 | 欧美日韩国产专区 | 美女视频黄a视频全免费网站色 | 国产欧美在线播放 | 乱妇伦交 | 亚洲视频一区二区三区 | 国产a视频精品免费观看 | 欧美网址在线观看 | 久久国产经典 | 欧美交配 | 欧美 日韩 亚洲另类专区 | 久久频道毛片免费不卡片 | 欧美一级色图 | 亚洲最新在线观看 | 欧美阿v高清资源在线 | 在线观看免费精品国产 | 国产成人久久 | 黄色在线免费观看网址 | 日韩成人在线电影 | 亚洲另类在线观看 | 成人日韩在线 | 伊人逼逼| 免费观看国产精品 | 欧美试看 | 欧美啊v在线观看 | 亚洲精国产一区二区三区 | 日韩欧美亚洲综合 | 久久精品一区二区影院 | 亚洲 欧美 自拍 另类 欧美 | 欧美国产成人精品一区二区三区 | 国产手机在线αⅴ片无码观看 | 欧美精品一区二区三区视频 | 伊人精品久久久大香线蕉99 | 国产91精品黄网在线观看 | 久青草国产视频 |