2017-03-10 174 views
3

我在我的页面上使用jquery,并没有其他部分的问题。即使$ .post和$ .get工作正常。

现在我试图评估图像是否有任何问题,并试图验证码:正如你看到的我已经缩短

Uncaught TypeError: $(...).error is not a function 
at app.js:53 
(anonymous) @ app.js:53 

$("#bib").error(function(){ 
    //nothing now 
}); 

我很奇怪,为什么我得到这个错误代码来隔离问题,但你得到了整个想法。目前,这些jQuery的来源包括内页:

https://code.jquery.com/jquery-3.1.0.min.js https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js

任何想法,为什么出现这种情况?

+1

看起来像它已在3.0中删除。在2.4中工作正常,然后不在3.0中(使用jsfiddle)。试试'.on'版本,详情请看https://api.jquery.com/error/ –

+1

['.error()'](https://api.jquery.com/error/):“_As jQuery 1.8,.error()方法已被弃用。使用.on(“error”,处理程序)将事件处理程序附加到错误事件._“ – Andreas

+1

@Andreas不推荐使用。你能找到他们删除它的地方吗?不在API页面上声明。 –

回答

2

使用这个代替(如前所述,.error已被删除)。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
<script> 

$("#bib").on('error', function(){ 
    //nothing now 
}); 

</script> 
0

从jQuery升级指南在:https://jquery.com/upgrade-guide/3.0/#breaking-change-load-unload-and-error-removed

Breaking change: .load(), .unload(), and .error() removed

These methods are shortcuts for event operations, but had several API limitations. The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $("img").on("load", fn) .

相关问题