jQuery错误-无法调用未定义的方法'indexOf' [英] jQuery Error - Cannot call method 'indexOf' of undefined
问题描述
我有以下代码可解决z-index中所有内容的Flash跳动问题:
I have this code to fix the issue of flash hopping over all your content in the z-index:
$("iframe").each(function(){
var ifr_source = $(this).attr('src');
var wmode = "wmode=opaque";
if(ifr_source.indexOf('?') != -1) {
var getQString = ifr_source.split('?');
var oldString = getQString[1];
var newString = getQString[0];
$(this).attr('src',newString+'?'+wmode+'&'+oldString);
}
else $(this).attr('src',ifr_source+'?'+wmode);
});
由于某种原因,我在indexOf上遇到错误,并且该站点中断了.但是奇怪的是,它并没有完全打破它,只是我在上面的一个CSS调整大小的修复程序.
For some reason, i'm getting errors on the indexOf, and it's breaking the site. But oddly, it's not breaking it entirely, just one css resize fix I have on there.
未捕获的TypeError:无法调用未定义的方法'indexOf'
Uncaught TypeError: Cannot call method 'indexOf' of undefined
站点在这里: http://syndex.me
很想知道为什么会这样.
Would love to know why this is happening.
推荐答案
直接从this
获取src
.您无需为此创建整个jQuery对象.
Get the src
directly from this
. You do not need to create a whole jQuery object for this.
ifr_source = this.src;
作为奖励,即使未设置属性src
,this.src
也会返回一个空字符串,而jQuery的attr
返回undefined
,您必须在使用indexOf
之前执行检查.
As a bonus, this.src
returns an empty string even if the attribute src
is not set, whereas jQuery's attr
returns undefined
and you have to perform a check before using indexOf
.
这篇关于jQuery错误-无法调用未定义的方法'indexOf'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!