報錯:Uncaught TypeError: LightBox is not a constructor
大家?guī)臀铱纯创a,代碼跟視頻上的一樣啊,為什么不能alert 1出來。
報錯:Uncaught TypeError: LightBox is not a constructor ?
js:
;(function($) {
var LightBox = function() {
var self = this;
//創(chuàng)建遮罩和彈出框
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>
2016-09-05
var LightBox = new LightBox(); 加粗的要小寫,別沖突,或用其他的名字??!
2016-08-21
LightBox 不是構(gòu)造函數(shù)