layui获取单选框和多选框按钮选中事件
展开阅读全文

checkbox的html代码

 <input name="like1[write]" lay-skin="primary" title="写作" checked="" type="checkbox">
 <input name="like1[read]" lay-skin="primary" title="阅读" type="checkbox">
 <input name="like1[game]" lay-skin="primary" title="游戏" disabled="" type="checkbox">

radio的html代码

<input type="radio" name="sex" lay-filter="erweima" value="二维码" title="二维码">
<input type="radio" name="sex" lay-filter="erweima" value="图片" title="图片" >

获取多选框

layui.use('form', function () {
form.on('checkbox(switchTest)', function (data) { 
   layer.msg('开关checked:' + (this.checked ? 'true' : 'false'), {
      offset: '6px'
   });
});

获取单选框

layui.use('form', function () {
form.on('radio(switchTest)', function (data) {
  alert(data.elem);
  alert(data.value);//判断单选框的选中值
});