话不多说,上代码
window.onload = function () {
var HallNameId = $("#HallNameId").val();
//console.log(HallNameId);
var select = 'dd[lay-value=' + HallNameId + ']';
$('#hallName').siblings("div.layui-form-select").find('dl').find(select).click();
}
layui在select
标签中,会被渲染为dd列表,此时,我们赋值select标签已无太大的意义,需要对dd列表中的值设置选中
<div class="layui-form-item">
<label class="layui-form-label">选项</label>
<div class="layui-inline layui-show-xs-block">
<select id="hallName" name="hallName" lay-filter="hallName">
<option value="1">请选择</option>
<option value="1">测试1</option>
<option value="1">测试2</option>
<option value="1">测试3</option>
</select>
<div class="layui-unselect layui-form-select">
<div class="layui-select-title">
<input type="text" placeholder="请选择" value="请选择" readonly="" class="layui-input layui-unselect">
<i class="layui-edge" />
</div>
<dl class="layui-anim layui-anim-upbit">
<dd lay-value="1" class="layui-this">请选择</dd>
<dd lay-value="1" class="layui-this">测试1</dd>
<dd lay-value="1" class="layui-this">测试2</dd>
<dd lay-value="1" class="layui-this">测试3</dd>
</dl>
</div>
</div>
</div>
第二种方法
直接给select
赋值,然后重新渲染选择框
<div id="divHide" style="display:none">
<input type="hidden" id="exhibitorId" value=""/>
</div>
var topId = $('#exhibitorId', top.document);
console.log("exhibitorId ", topId.val());
layui.use(['form'], function () {
var form = layui.form;
$("#ExhibitorId").val(topId.val());
layui.form.render('select');
console.log("设置为上次的完毕 ", topId.val());
});