标签:char btn img asc 图片 meta 技术 div cli
创建一个数组,获取多选的
val()返回value值
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
$(document).ready(function () {
var data=new Array("0","1","2","3");
$("#tar").val(data);
})
</script>
<link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
<style>body{padding:20px;}.multi dl dd.layui-this{background-color:#fff}</style>
</head>
<body>
<form class="layui-form layui-form-pane" action="">
<div class="layui-form-item">
<label class="layui-form-label">多选</label>
<div class="layui-input-block">
<select multiple="multiple" lay-filter="test" id="tar">
<option value=""></option>
<option value="0" >A</option>
<option value="1">B</option>
<option value="2">C</option>
<option value="3" >D</option>
</select>
</div>
</div>
<button type="button" class="layui-btn layui-btn-normal" id="get-val">获取选中值</button>
</form>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript">
layui.config({
base: ‘js/‘,
})
layui.use([‘multiSelect‘],function() {
var $ = layui.jquery,form = layui.form,multiSelect = layui.multiSelect;
$(‘#get-val‘).click(function() {
var vals = [],
texts = [];
$(‘select[multiple] option:selected‘).each(function() {
vals.push($(this).val());
//push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度。
texts.push($(this).text());
})
console.dir(vals);
console.dir(texts);
})
form.on(‘select(test)‘,function(data){
console.dir(data);
})//把值转为文字,控制台输出
});
</script>
</body>
</html>
标签:char btn img asc 图片 meta 技术 div cli
原文地址:https://www.cnblogs.com/lvfang/p/9898611.html