layui 事件监听

Posted on 2021-04-01 11:52  zkx4213  阅读(249)  评论(0编辑  收藏  举报
<div class="layui-btn-group demoTable" style="float: right;">
  <button class="layui-btn layui-btn-sm" data-type="test1" style="margin-right: 0px; margin-bottom: 0px;"><i class="layui-icon">&#xe654;</i>测试1</button>
  <button class="layui-btn layui-btn-sm" data-type="test2" style="margin-right: 0px; margin-bottom: 0px;"><i class="layui-icon">&#xe654;</i>测试2</button>
  <button type="submit" class="layui-btn layui-btn-sm" id="test3" lay-submit lay-filter="test3">测试3</button>
  <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="test4">测试4</button>
</div>

<script>
layui.use(['upload','form','laydate','table','layer'], function () {
  
  var active = {
  test1: function(){
  layer.alert(1);
  }
  ,test2: function(){
  layer.alert(2);
  }
  };

  $('.demoTable .layui-btn').on('click', function(){
  var type = $(this).data('type');
  active[type] ? active[type].call(this) : '';
  });

  form.on('submit(test3)', function (data) {
    layer.alert(3)
  });
}
</script>

 



Copyright © 2024 zkx4213
Powered by .NET 9.0 on Kubernetes