js下拉菜单生成器dropMenu使用方法详解
(编辑:jimmy 日期: 2025/11/3 浏览:3 次 )
本文实例为大家分享了下拉菜单生成器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' "dropMeun-searchInput" type="text"></li>'
}
this.dataList.forEach(function(data, index) {
var item = _this.option.dataSrc "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 "htmlcode">
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;
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇:简述jQuery Easyui一些用法