我知道我可能会得到大量的支持,但我不在乎,这样的废话让我疯狂。这是我得到的:
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单击触发器给出错误'超出最大调用堆栈大小'
发布评论