Jquery单击触发器给出错误'超出最大调用堆栈大小' [英] Jquery click trigger gives error 'Maximum call stack size exceeded '

查看:78
本文介绍了Jquery单击触发器给出错误'超出最大调用堆栈大小'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可能会得到大量的支持,但我不在乎,这样的废话让我疯狂。这是我得到的:

I know I might get bunch of downvotes but I don't care, crap like this drives me insane. Here's what I got:

jq:

function attFile(){
   $("#theFileInput").trigger('click');
};

html:

<a href="#" id="attachfile" onclick="attFile();">
<input type="file" id="theFileInput" style="display:none" />

它不起作用。我检查了整个stackoverflow,我使用了实际工作的人的jsfiddles,他们在这里失败了。例如:

And it doesn't work. I've check entire stackoverflow, I've used jsfiddles from people that actually work and they fail here. For instance:

$('#attachfile').click(functcion () {
$("#theFileInput").trigger('click'); // or triggerHandler or click()
});

function attFile(event){
event.preventDefault();
$("#theFileInput").trigger('click');
};

一切都失败了。事件会给我调用undefined,而rest会给我 Uncaught RangeError:超出最大调用堆栈大小如果我用 alert打破它(jq please); 在第一行,取决于我使用的代码,一个将永远循环,而其他人将显示警报但不点击该死的文件输入。

It all fails. Event will give me "call to undefined", while rest gives me Uncaught RangeError: Maximum call stack size exceeded If I break it with alert("jq please"); at the first line, depending on the code I use, one will loop forever, while others will show the alert but not click the damn file input.

推荐答案

Html:

<a href="javascript:void(0);" id="attachfile">Click on me </a>
<input type="file" id="theFileInput" style="display:none" />

JS:

$('#attachfile').click(function () {
$("#theFileInput").trigger('click');
});

示例

Sample

这篇关于Jquery单击触发器给出错误'超出最大调用堆栈大小'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆