How to modify the select value in layui: First add the code "" in html5 to obtain Initial value; then set the values of select and radio button in js.

The operating environment of this tutorial: Windows 7 system, layui version 2.4. This method is suitable for all brands of computers.
Dynamicly set the select value of layui
Recommended: "javascript basic tutorial" "layUI tutorial"
Add the following code in html5 to obtain the initial value.
<input id="ggg" style="display: none;" value="{$hopedepart}" />
<input id="ddd" style="display: none;" value="{$sex}" />Then set the values of select and radio button in js.
<script>
function firstload() {
var str = "#hopedepart option[value='" + $("#ggg").val() + "']";
var sex = "input:radio[value='" + $("#ddd").val() + "']";
// document.write(sex);
$("#hopedepart option[value='']").removeAttr("selected"); //2.移除默认选项的选中状态 removeAttr("selected")
$(str).attr("selected", "selected");
$(sex).attr('checked', 'true');
}
firstload();
</script>Give a specific example
html
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<!--引入jQuery-->
<input type="hidden" id="position_hidden_id" th:value="${staff?.position}">
<select name='position' id="position_id" lay-filter='aihao'>
<option value=''></option>
<option value='前端开发'>前端开发</option>
<option value='后端开发'>后端开发</option>
<option value='产品'>产品</option>
<option value='测试'>测试</option>
<option value='UI'>UI</option>
<option value='人事'>人事</option>
<option value='财务'>财务</option>
<option value='市场'>市场</option>
<option value='总经理'>总经理</option>
</select>
<script>
//alert("ggg");
$(document).ready(function(){
var key1=$("#position_hidden_id").val();
//根据值让option选中
$("#position_id option[value='"+key1+"']").attr("selected","selected");
});
</script>The above is the detailed content of Layui method to modify the value of select. For more information, please follow other related articles on the PHP Chinese website!
How to import old phone into new phone from Huawei mobile phone
Python online playback function implementation method
How to check memory
Usage of urlencode function
How to solve the problem of not being able to create a new folder in Win7
How to get page elements using javascript
lightbox.js
How to solve the 0x0000006b blue screen