由于
这样的下拉框必须加载from模块,所以改了一下layUI的另外一种下拉
.L-select-item{
width: 100px;
position: relative;
}
.Lselect{
display: flex;
justify-content: space-between;
align-items: center;
width: 175px;
}
.L-edge{
border-color: transparent;
}
.L-select-item .L-edge{
position: absolute;
right: 10px;
margin-top: -3px;
top: 50%;
border-width: 6px;
border-top-color: #C2C2C2;
border-style: solid;
}
.L-select-item .Linput{
cursor: pointer;
min-height: 100%;
}
<link rel="stylesheet" href="./layui-v2.7.2/layui/css/layui.css">
<script src="./layui-v2.7.2//layui/layui.js"></script>
<div class="Lselect">
<label>下拉菜单:</label>
<div class="L-select-item">
<input type="text" id="lselect" class="layui-input Linput" readonly />
<i class="L-edge" id="LEdge"></i>
</div>
</div>
<script>
layui.use('dropdown', function() {
var dropdown = layui.dropdown
dropdown.render({
//可绑定在任意元素中
elem: '#lselect' ,
data: [{
title: '2秒',
id: 1,
}, {
title: '10秒',
id: 2,
}, {
title: '10分钟',
id: 3,
},{
title: '一小时',
id: 4,
}],
//菜单被点击的事件,基本就是利用这个获取完选中的剩下的就是css的事情了
click: function(obj) {
// 这里能直接获取绑定的input
lselect.value = obj.title
}
});
});
</script>