雅安论坛

标题: Uncaught ReferenceError: layer is not defined [打印本页]

作者: 匿名    时间: 2021-8-3 16:06
标题: Uncaught ReferenceError: layer is not defined
Uncaught ReferenceError: layer is not defined
  1. 这样写就对了layui.use("layer",function(){
  2. }
  3. )
复制代码
  1.    <img src="<?php echo $row['fj']?>"   width="60px" height="30px" class="layui-upload-img"
  2.      onclick="previewImg(this)">查看附件

  3.    <script>
  4.      
  5.   function previewImg(obj) {
  6.      
  7.   
  8.     layui.use("layer",function (){

  9.         var img = new Image();  
  10.         img.src = obj.src;
  11.         //var height = img.height + 50; // 原图片大小
  12.         //var width = img.width; //原图片大小
  13.         var imgHtml = "<img src='" + obj.src + "' width='500px' height='500px'/>";  
  14.         //弹出层
  15.         layer.open({  
  16.             type: 1,  
  17.             shade: 0.8,
  18.             offset: 'auto',
  19.             area: [500 + 'px',550+'px'],  // area: [width + 'px',height+'px']  //原图显示
  20.             shadeClose:true,
  21.             scrollbar: false,
  22.             title: "图片预览", //不显示标题  
  23.             content: imgHtml, //捕获的元素,注意:最好该指定的元素要存放在body最外层,否则可能被其它的相对元素所影响  
  24.             cancel: function () {  
  25.                 //layer.msg('捕获就是从页面已经存在的元素上,包裹layer的结构', { time: 5000, icon: 6 });  
  26.             }  
  27.         });
  28.     }

  29. )
  30.      }
  31. </script>
复制代码
(, 下载次数: 28)






欢迎光临 雅安论坛 (https://www.yaanbbs.net/) Powered by Discuz! X3.4