Layui select实现主动赋值和触发选择事件,及radio实现可取消

Layui select赋值,并主动触发选择事件

// Layui select赋值,并主动触发选择事件
// Input: selectId:ID选择器,selectFilter:lay-filter名称,value:需要的赋值,text:显示文本值
function setSelect(selectId, selectFilter, value, text){
    //赋值
    $(selectId).find("option[value="+value+"]").prop("selected",true);
    $(selectId).parent().find(".layui-select-title").find("input").val(text);
    //触发事件
    layui.event("form", "select("+selectFilter+")", {value: value});        
}

Layui radio点击事件,实现可选中可取消

// Layui radio点击事件,实现可选中可取消
// filterName:lay-filter名称
layui.form.on("radio(filterName)",function(data){
    if($(this).attr("checked")) {
         $(this).removeAttr("checked")
     } else {
         $(this).attr("checked", "true")
     }
     layui.form.render();
});

 

posted @ 2024-01-23 11:01  失恋的蔷薇  阅读(100)  评论(0编辑  收藏  举报