layer报错layer.js:2 Uncaught TypeError: s.parents is not a function

layer报错layer.js:2 Uncaught TypeError: s.parents is not a function

layui

订阅专栏
layer报错layer.js:2 Uncaught TypeError: s.parents is not a function
晕死,很简单的问题。就是不能使用layer.msg()输出object。因为object是对象,使用console.log()就好了。

错误截图


错误代码&解决方案
PS:layer.msg(),相当于alert,只能输出变量跟字符串。不能输出对象object。使用console.log(data),输出即可。

错误代码:

我们看到,代码中使用了layer.msg(data)输出了data,data是object,不是字符串跟变量。不能使用layer.msg输出。

<script>
    //引用layui的模块化,需要什么就加载什么
      layui.use(['form'],function(){
         var form = layui.form
             ,layer = layui.layer;
         form.on('submit(submitSystem)',function(data){
            layer.msg(data);//data是object。layer.msg不能输出object。否则就会报错(layer.js:2 Uncaught TypeError: s.parents is not a function)
           console.log(data);
         });
      });
  </script>

11
解决方案:用console.log(data),就不会有问题了。

  <script>
    //引用layui的模块化,需要什么就加载什么
      layui.use(['form'],function(){
         var form = layui.form
             ,layer = layui.layer;
         form.on('submit(submitSystem)',function(data){
            //layer.msg(data);//data是object。layer.msg不能输出object。否则就会报错layer.js:2 Uncaught TypeError: s.parents is not a function
           console.log(data);
         });
      });
  </script>
————————————————
版权声明:本文为CSDN博主「@Winner」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zxh7770/article/details/101212633

 

posted @ 2022-06-17 14:34  前端白雪  阅读(1374)  评论(0编辑  收藏  举报