jQuery 未捕获的类型错误:无法读取未定义的属性“nodeName”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9362583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot read property 'nodeName' of undefined
提问by David Nelband
this problem appears only in joomla -
这个问题只出现在joomla -
im trying to use the contentflow plugin with my joomla site
我试图在我的 joomla 网站上使用 contentflow 插件
this is the plugin site - http://www.Hymansasylum.eu/ContentFlow/
这是插件站点 - http://www.Hymansasylum.eu/ContentFlow/
this is my site - http://2-dweb.com/RND/
这是我的网站 - http://2-dweb.com/RND/
as you can see it doesnt work - it just stays on the loading phase forever
如您所见,它不起作用 - 它永远停留在加载阶段
upon closer inspection i can see that there is a problem with this code:
经过仔细检查,我可以看到此代码存在问题:
if (this.content.nodeName == "IMG") {
CFobj._imagesToLoad++;
var foobar = function () {
CFobj._imagesToLoad--;
this.image = this.content;
this.setImageFormat(this.image);
if ( CFobj.conf.reflectionHeight > 0) {
this.addReflection();
}
this.initClick();
CFobj._addItemCueProcess(true);
}.bind(this);
if (this.content.complete && this.content.width > 0)
window.setTimeout(foobar, 100);
else if (this.Browser.IE && !this.content.onload) {
var self = this;
var t = window.setInterval( function () {
if (self.content.complete && self.content.width > 0) {
window.clearInterval(t);
foobar();
}
}, 10);
}
else
this.content.onload = window.setTimeout(foobar, 100);
}
else {
this.initClick();
CFobj._addItemCueProcess(true);
}
};
with the first line - it says "Uncaught TypeError: Cannot read property 'nodeName' of undefined "
第一行 - 它说“未捕获的类型错误:无法读取未定义的属性'nodeName'”
but this thing works on my desktop html file and on the plugin site it self!
但这东西适用于我的桌面 html 文件和插件站点!
why doesnt it work on my joomla site? its not a conflict thing - im using no-conflict and i have other jquery plugins that work
为什么它在我的 joomla 网站上不起作用?这不是冲突的事情 - 我使用无冲突,我有其他有效的 jquery 插件
update:
更新:
rob w helped me with this error: "Change the first line to if (this.content && this.content.nodeName == "IMG") {. That solves the problem"
rob w 帮我解决了这个错误:“将第一行更改为 if (this.content && this.content.nodeName == "IMG") {。这就解决了问题”
and it did, but now another error appears:
确实如此,但现在出现了另一个错误:
initClick: function () {
var cItem = this.clickItem;
this[this._activeElement].addEvent('click', cItem, false);
},
the error - Uncaught TypeError: Cannot call method 'addEvent' of undefined
错误 - 未捕获的类型错误:无法调用未定义的方法“addEvent”
回答by Techie
As the error explains "Uncaught TypeError: Cannot read property 'nodeName' of undefined " The element is not available when the script tries to access it. You can solve this in two ways.
正如错误解释的那样“未捕获的类型错误:无法读取未定义的属性 'nodeName'” 当脚本尝试访问该元素时,该元素不可用。您可以通过两种方式解决此问题。
- Try to wrap to code with a document.ready.
- You can check whether the element is available before accessing it. To get this done use a if clause.
- 尝试使用 document.ready 包装到代码。
- 您可以在访问之前检查该元素是否可用。要完成此操作,请使用 if 子句。
回答by web_developer
Solved this.
解决了这个问题。
I am using bootstrap.css version 3.3.7 and bootstrap.js version 4.0.0.
我使用的是 bootstrap.css 版本 3.3.7 和 bootstrap.js 版本 4.0.0。
By changing bootstrap.js to version 3.3.7 my issue got resolved!!!
通过将 bootstrap.js 更改为 3.3.7 版,我的问题得到了解决!!!
回答by Prasanth K C
Load your script only after loading all the elements into DOM.
仅在将所有元素加载到 DOM 后才加载您的脚本。
Your script should be called at the bottom of the page like this
您的脚本应该像这样在页面底部调用
<html>
<head></head>
<body>
<!--HTML Elements here-->
<script type="text/javascript" src="yourScript.js"></script>
</body>
</html>
If you are using jquery, you can include the script file anywhere in your page if it is wrapped in document.ready
, like this:
如果您使用 jquery,您可以将脚本文件包含在页面中的任何位置(如果它被包裹在 中document.ready
,就像这样:
$(document).ready(function(){
// your code here..
});
回答by i89
It is important that you use class="content"
. The structure should be:
使用class="content"
. 结构应该是:
<div class="ContentFlow" id="cover-menu">
<div class="flow">
<div class="item" >
<div class="content">
//your stuff
</div>
</div>
</div>
</div>
回答by Marcos Barreto
was with this error. I made the correction leaving all the js and css of the bootstrap with the same version. In my case I used the latest version of each: https://getbootstrap.com/docs/4.4/getting-started/download/
有这个错误。我进行了更正,将引导程序的所有 js 和 css 保留为相同版本。就我而言,我使用了每个的最新版本:https: //getbootstrap.com/docs/4.4/getting-started/download/