文件提交问题

发布于 2024-11-30 22:55:56 字数 866 浏览 3 评论 0原文

<form method="POST" enctype="multipart/form-data" action="http://site.com/img">
File: <input type="file" name="file" id="abc" /><br/>  
ID: <input type="text" name="someId" value="123"/>
<input id="submitFormButton" type="submit" value="Upload" name="Upload"> 
</form>

<input type="button" id="btnEditAvatar" value="fakeButton"/>

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

仅在 IE 中出现问题。 当按“abc”按钮选择文件时,它可以工作(关闭文件对话框后,文件上传),但是当我按“btnEditAvatar”按钮时,关闭文件对话框后没有任何反应。

我尝试使用“单击”功能而不是“更改”。我尝试使用“setTimeout”函数调用它,并且还尝试使用“onpropertychange”事件处理程序。

http://jsfiddle.net/streamcode9/hAnbQ/

<form method="POST" enctype="multipart/form-data" action="http://site.com/img">
File: <input type="file" name="file" id="abc" /><br/>  
ID: <input type="text" name="someId" value="123"/>
<input id="submitFormButton" type="submit" value="Upload" name="Upload"> 
</form>

<input type="button" id="btnEditAvatar" value="fakeButton"/>

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

Problem occurs in IE only.
When choose file by pressing on "abc" button it works(after closing file dialog, file is uploaded), but when I press on "btnEditAvatar" button, nothing is happened after closing file diaog.

I've tried to use "click" function instead of "change". I've tried to call it with "setTimeout" function and I also tried to use "onpropertychange" event handler.

http://jsfiddle.net/streamcode9/hAnbQ/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2024-12-07 22:55:56

相反,如果尝试单击提交按钮,为什么不直接提交表单呢?

$("#abc").change(function() { $(this).closest('form').submit() });

Instead if trying to click the submit button, why not just submit the form?

$("#abc").change(function() { $(this).closest('form').submit() });
枯寂 2024-12-07 22:55:56

尝试以下任一方法:

$("#btnEditAvatar").bind("click", function () { $("#submitFormButton").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

这会将其绑定到提交。

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("change"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

这将其绑定到触发提交点击的更改

try either of these:

$("#btnEditAvatar").bind("click", function () { $("#submitFormButton").trigger("click"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

This binds it to submit.

$("#btnEditAvatar").bind("click", function () { $("#abc").trigger("change"); });
$("#abc").change(function() { $("#submitFormButton").trigger("click"); });

this binds it to change which triggers the submit click

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文