[英]TypeOf issue with jquery code
I am having an issue with some code... 我对某些代码有疑问...
This is the code: 这是代码:
(function($) {
$.fn.inc = function(url, transform, post, t) {
return this.length && url ? this.each(function() {
t = $(this);
$.ajax({
url: url,
success: function(txt, jqXHR, textStatus) {
t.html($.isFunction(transform) ? transform(txt, url) : txt);
$.isFunction(post) && post(url, jqXHR, textStatus);
}
});
}) : this;
};
$(function() {
$('[class*="inc:"]').each(function() {
var match = /inc:(\S+)/.exec(this.className || '');
if(typeOf(match[1]) != "undefined")
match && $(this).inc(unescape(match[1]));
});
});
})(jQuery);
and on line 18 it's point to this error: 在第18行,它指向此错误:
ReferenceError: typeOf is not defined
if(typeOf(match[1]) != "undefined")
What's wrong with the code? 代码有什么问题?
This error points to: 此错误指向:
TypeError: a is null
**return (a.ownerDocument || a) !== n && m(a), t(a, b)**
The operator you are looking for is typeof
all in lowercase . 您要查找的运算符是
typeof
全部小写 。 JavaScript is case sensitive. JavaScript区分大小写。
And note that it is an operator, not a function, so you don't need the parentheses (although they don't actually hurt). 请注意,它是一个运算符,而不是一个函数,因此您不需要括号(尽管它们实际上并没有造成伤害)。
Note also that the .exec()
method can return null
, so you need whether match
is null
before you try to use it as an array: 还要注意,
.exec()
方法可以返回null
,因此在尝试将其用作数组之前 ,您需要match
是否为null
:
if (match != null && typeof match[1] != undefined)
Or just: 要不就:
if (match && typeof match[1] != undefined)
But you shouldn't need to test if match[1]
is undefined
, because if match
itself is not null
then that means your regex matched including the substring match. 但是您不需要测试
match[1]
是否undefined
,因为如果match
本身不为null
则意味着您的正则表达式匹配项包括子字符串匹配项。 So the following should be OK: 所以以下应该可以:
if (match)
$(this).inc(unescape(match[1]));
这应该是typeof
(小“ O”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.