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

  • Layui select实现主动赋值和触发选择事件,及radio实现可取消已关闭评论
  • 94 次浏览
  • A+
所属分类:Web前端
摘要

 


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(); });