Jquery单击触发器给出错误'超出最大调用堆栈大小'

编程入门 行业动态 更新时间:2024-10-20 11:42:46
本文介绍了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单击触发器给出错误'超出最大调用堆栈大小'

本文发布于:2023-10-26 23:56:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   触发器   单击   大小   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!