jquery触发器:当我点击文本链接时,如何在输入中触发浏览文件? [英] jquery trigger: how can I trigger the browse file in the input when I click on a text link?
本文介绍了jquery触发器:当我点击文本链接时,如何在输入中触发浏览文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关注此帖子 a>,我有另一个发行者 - 当我点击文本链接时,如何在输入中触发浏览文件?
Following up on this post, I have another issuer - how can I trigger the browse file in the input when I click on a text link?
基本上我想隐藏表单,但它点击上传文字链接时会触发。
Basically I want to hide the form but it will be triggered when you click on the upload text link.
<a href="#" class="upload">upload</a>
<form action="upload.php" method="post" enctype="multipart/form-data" id="myForm" style="display:none;">
<input type="file" multiple="multiple" name="file[]" />
<input type="submit" name="upload" value="Submit"/>
</form>
<div id="output"></div>
这是我的工作Javascript代码:
This is my working Javascript code:
$(document).ready(function(){
$('.upload').click(function(){
$(this).trigger($('input[type=file]'));
return false;
});
$('input[type=file]').change(function() {
$('#myForm').ajaxSubmit({
target: '#output'
});
});
});
推荐答案
不能使用 style =display:none;
使用 style =visibility:hidden;
,我将触发器改为点击:
and I changed trigger to click:
$('.upload').click(function(){
$('input[type=file]').click();
return false;
});
推论:
输入字段不会通过 display:none
发送到服务器,但会显示 :hidden
。
The input fields will not be sent to the server with display:none
, but will be with visibility:hidden
.
这篇关于jquery触发器:当我点击文本链接时,如何在输入中触发浏览文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文