为了账号安全,请及时绑定邮箱和手机立即绑定

报错:Uncaught TypeError: LightBox is not a constructor

大家帮我看看代码,代码跟视频上的一样啊,为什么不能alert 1出来。

报错:Uncaught TypeError: LightBox is not a constructor  


js:

;(function($) {

var LightBox = function() {

var self = this;

//创建遮罩和弹出框

this.popupMask = $("<div id='G-lightbox-mask'></div>")

this.popupWin = $("<div id='G-lightbox-popup'></div>")

//保存body

this.bodyNode = $(document.body);

//渲染剩余的DOM插入到body;

this.renderDOM();

};

LightBox.prototype = {

renderDOM: function() {

alert("1");

}

};

window["LightBox"] = LightBox; 

})(jQuery);


html页面

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<script src="js/jquery-2.2.1.min.js"></script>

<script src="js/LightBox.js"></script>

</head>

<body>  


<script>

$(function(){

var LightBox = new LightBox();

})

</script>

</body>

</html>


正在回答

2 回答

var LightBox = new LightBox(); 加粗的要小写,别冲突,或用其他的名字!!

0 回复 有任何疑惑可以回复我~

LightBox 不是构造函数

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

报错:Uncaught TypeError: LightBox is not a constructor

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号