layui调用自定义方法提示未定义的解决办法

问题:

  1. layui.use(['layer', 'form', 'element'], function(){
  2. var layer = layui.layer
  3. ,form = layui.form
  4. ,element = layui.element
  5.     function test(){
  6.     //JS代码
  7.     }
  8. });

调用test()时提示未定义

解决办法:

  1. layui.use(['layer', 'form', 'element'], function(){
  2. var layer = layui.layer
  3. ,form = layui.form
  4. ,element = layui.element
  5.    window.test = function(){
  6.     //JS代码
  7.     }
  8. });


你可能感兴趣的:(前端-Layui)