在链接上打开文件浏览器,单击 [英] Open File Browser on Link Click

查看:76
本文介绍了在链接上打开文件浏览器,单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制Facebook上用于更改个人资料图片的照片上传脚本.我希望用户单击链接,它会自动打开文件浏览器,然后当他们单击确定时,它将提交图像.

I'm trying to duplicate the photo upload script used on Facebook for changing your profile picture. I'm wanting for the user to click on a link and it automatically opens the file browser, and then when they click ok it submits the image.

我想知道的是,如何在单击链接时触发文件浏览器,以及当他们单击确定时如何触发提交文件浏览器?

What I'm wanting to know is how do you trigger the file browser on clicking a link, and how do you trigger to submit it when they press ok?

我已经有一个表格,但想使其更加简化.

I already have a form, but want to make it more streamlined.

当前脚本:

<a href="#" data-reveal-id="changeImage"><i class="fa fa-pencil"></i> Edit Client Image</a>
<div id="changeImage" class="reveal-modal">
<form action="view.php" enctype="multipart/form-data" method="post" name="imgForm" id="imgForm">
    <input type="file" name="clientImage" id="clientImage" accept="image/*" />
    <input name="doEditImg" type="submit" id="doEditImg" value="Save" />
</form>
</div>

推荐答案

我使用以下代码解决了这个问题.

I worked this out with the following code.

链接:<a href="#" id="changeImage"><i class="fa fa-pencil"></i> Edit Client Image</a>

表格:<form action="view.php" enctype="multipart/form-data" method="post" name="imgForm" id="imgForm"><input type="file" name="clientImage" id="clientImage" style="visibility:hidden;" accept="image/*" onchange="this.form.submit()" /></form>

jQuery:

$('#changeImage').click(function(){
    $('#clientImage').trigger('click');
    return false;
});

这篇关于在链接上打开文件浏览器,单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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