jquery设置layui表单select/checkbox/radio选中/取消状态checked

JQuery 849 0 2022-02-11

jquery设置layui表单select/checkbox/radio选中/取消状态checked

select状态设置:

<select id="sort" name="sort" lay-verify="required">
<option value="1">类型1</option>
<option value="2">类型2</option>
<option value="3">类型3</option>
 </select>

$('#sort option').each(function(){
if($(this).val()=='xxx'){
$('#sort').find("option[value='xxx']").attr("selected",true);
}
})


checkbox状态设置:

<input type="checkbox" name="j_tag[]" value="推荐" title="推荐">
<input type="checkbox" name="j_tag[]" value="置顶" title="置顶">

var v_tag='推荐,置顶';
var arr=v_tag.split(',');
$("input[name='j_tag[]']").each(function(){
var s=arr.indexOf($(this).val());
if(s>-1){
$(this).prop("checked","true");
};
});


radio状态设置:


<input type="radio" name="type" value="类型1" title="类型1">
<input type="radio" name="type" value="类型2" title="类型2">
<input type="radio" name="type" value="类型3" title="类型3">

$("input[name=j_type][value='类型2']").prop("checked","true");


注意:

删除checked代码是:$('#id').removeAttr("checked");

上一篇:jquery获取实时滚动条高度(可用于显示/隐藏/固定div动作)

下一篇:jQuery 常用方法汇总学习使用

讨论数量:0

请先登录再发表讨论。 2024-04-19

天涯网魂
3 杠 5 星
TA 的文章
TA 的随言
TA 的资源链