我在jQuery中具有以下功能:
$('canvas').createWindow('xyz', 500, 600);
后面的js代码是:
var $ = function(element) {
if (this.constructor !== $) {
return new $(element);
}
alert(element);
var windowObj = document.getElementById(element);
this.createWindow = function(src, width, height) {
if(width != "" && height != "") {
windowWidth = windowObj.style.width = width + 'px';
windowHeight = windowObj.style.height = height + 'px';
}
};
};
但是问题是
js
说windowObj是null
,但是alert(element)
可以正常工作!有任何想法吗? 最佳答案
您是否在DOM就绪或窗口加载时执行此操作?您是否有ID为canvas
的元素?您不是将节点名与ID混淆了吗?