jQuery 未捕获的 TypeError: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32231036/
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: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply is not a function
提问by TaGiang
Please help me. This is an error when I use jQuery
in ASP.NET MVC.
请帮我。这是我jQuery
在 ASP.NET MVC 中使用时的错误。
Uncaught TypeError: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply is not a function Uncaught TypeError: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply is not a function
Uncaught TypeError: ((x.event.special[i.origType] || (intermediate value)).handle || i.handler).apply 不是函数 Uncaught TypeError: ((x.event.special[i.origType] ] || (中间值)).handle || i.handler).apply 不是函数
The code that causes this is:
导致这种情况的代码是:
$('#btnClick').click(function(){ //code })
回答by smoksnes
In my case the error was caused by binding events to functions that didn't exist. I had removed functions that I didn't know was bound to events.
在我的情况下,错误是由将事件绑定到不存在的函数引起的。我删除了我不知道绑定到事件的函数。
See snippet below:
见下面的片段:
var foo = {
bar1: function(){
alert('working');
}
};
// Working
$('body').on('click', '.my-button', foo.bar1);
// Not Working because bar2 doesn't exist
$('body').on('click', '.my-button', foo.bar2);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="my-button">Click me</span>
It will produce:
它将产生:
Uncaught TypeError: ((n.event.special[g.origType] || (intermediate value)).handle || g.handler).apply is not a function
未捕获的 TypeError: ((n.event.special[g.origType] || (intermediate value)).handle || g.handler).apply 不是函数
回答by Edwin Mendez
If this is helpful to anyone this can be also because an event handler function is declared twice.
如果这对任何人都有帮助,这也可能是因为事件处理函数被声明了两次。
A coworker of mine coded the event as 'on' twice and I solved (Fool challenge by the way).
我的一个同事两次将事件编码为“on”,我解决了(顺便说一句,“傻瓜挑战”)。
For example if you have a typing mistake:
例如,如果您有打字错误:
$(document).on('change', '#selectInput').on('change', '#selectInput', function () {});
Must be:
必须是:
$(document).off('change', '#selectInput').on('change', '#selectInput', function () {});
回答by a20
In my case I had typed
就我而言,我输入了
$('body').click('click','.delete_item',function(e){})
When I had meant to type:
当我打算输入时:
$('body').on('click','.delete_item',function(e){})
changing that click
to on
removed the error.
改变它click
以on
消除错误。
回答by adrianthedev
I had an event bound on a selector that didn't exist anymore.
我在一个不再存在的选择器上绑定了一个事件。
$(document).on('click', '.js-test', App.test);
$(document).on('click', '.js-test', App.test);
I deleted the .js-test
div and forgot. That was causing the error on my end.
我删除了.js-test
div并忘记了。这导致了我的错误。
回答by Fabian Picone
The only fix for me was to return false
at the end.
对我来说唯一的解决办法是false
最后返回。
var button = $('<button>').click(function () {
// do something
return false;
});
See this question. It had to do with propagation.
看到这个问题。它与传播有关。
回答by Avinash Jain
In my case it worked after declaring the delegation inside $(document).ready( function() {})
;
在我的情况下,它在内部声明委托后起作用$(document).ready( function() {})
;
回答by Mehmet Ali Uysal
This problem happens, try to adding listener not existing html object. if too many listener you have and you cant found which element not exist, debug jquery file after beauty format.
发生此问题,尝试添加侦听器不存在的 html 对象。如果您有太多的侦听器而找不到哪个元素不存在,请在 Beauty 格式后调试 jquery 文件。
in jquery file, find dispatch function. at second dimension for loop statement add OR operator and log t variable;
在 jquery 文件中,找到调度函数。在循环语句的第二维添加 OR 运算符和 log t 变量;
|| console.log(t)
|| 控制台.log(t)
for (t.currentTarget = o.elem, i = 0;
(r = o.handlers[i++]) && !t.isImmediatePropagationStopped();)(!t.namespace_re || t.namespace_re.test(r.namespace)) && (t.handleObj = r, t.data = r.data, s = ((p.event.special[r.origType] || {}).handle || r.handler).apply(o.elem, l) || console.log(t), void 0 !== s && (t.result = s) === !1 && (t.preventDefault(), t.stopPropagation()));
Read last throwed console response before error. It's help find which element not exist in html doc.
读取错误前最后抛出的控制台响应。它有助于查找 html 文档中不存在的元素。
Finally check html obj exist in doc with jquery, problem will be solved.
最后用jquery检查doc中是否存在html obj,问题就解决了。
if($('.cartProduct .close-button').length>0)
$('.cartProduct .close-button').click(function{
});
回答by SamT
I encountered the same issue recently. I found that it was my mistake in handling jquery events. Instead of
我最近遇到了同样的问题。我发现这是我在处理 jquery 事件时的错误。代替
$('#btnClick').click(function(){ //code })
Try this,
尝试这个,
$('#btnClick').on('click', function(){ //code })
It worked for me. Hope it helps.
它对我有用。希望能帮助到你。
回答by Jan
I guess it's a little late, but to anyone encountering this issue: check your html code for multiple jquery imports. Any additional import might mess up previously registered handles/plugins/etc.
我想这有点晚了,但是对于遇到此问题的任何人:检查您的 html 代码是否有多个 jquery 导入。任何额外的导入可能会弄乱以前注册的句柄/插件/等。
回答by tated
Another way I've gotten this error is by absentmindedly putting a function where a function name should go:
我得到这个错误的另一种方法是心不在焉地把一个函数放在函数名应该去的地方:
wrong:
错误的:
$('.foo').click($('.bar').trigger('click'));
right:
对:
$('.foo').click(function () {
$('.bar').trigger('click');
});
also right:
也对:
$('.foo').click(triggerBarClick);
function triggerBarClick() {
$('.bar').trigger('click');
}