jQuery表单上传插件:如何将其减少到一键式? [英] Jquery form upload plugin: how to reduce it to one click?

查看:102
本文介绍了jQuery表单上传插件:如何将其减少到一键式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jquery表单插件处理上传的文件,

I am using jquery form plugin to handle uploading files,

这是我的表格,

    <form action="upload.php" method="post" enctype="multipart/form-data" id="myForm">
  <input type="file" multiple="multiple" name="file[]" />
  <input type="submit" name="upload" value="Submit"/>
</form>
<div id="output"></div>    

jQuery,

    $('#myForm').submit(function() {

        $(this).ajaxSubmit({
        target: '#output'
        });

        return false;

   });

这种想法的后备之处在于,您必须先单击两次,然后再上传文件-您必须单击以浏览文件,然后单击提交按钮.

The fallback of this idea is that you have to click twice before uploading the files - you have to click to browse the files and then clicking the submit button.

如何将其减少为个点击?理想情况下,当您从桌面上选择文件并在浏览窗口/弹出窗口中单击确定"时,我希望它自动触发提交.

How can I reduce it to one click? Ideally I want it to trigger the submit automatically when you have selected the files from the desktop and click ok on the browse window/ popup.

有可能吗?

另一个说明:为什么它不能在Chrome,IE和Safari上运行(仅在Firefox和Opera上运行)-表单将在这些浏览器上提交,但是我已经将submit()设置为return false?

Another note: why it does not work on Chrome, IE, and Safari (it only works on Firefox and Opera) - the form will be submitted on these browsers but I have already set the submit() to return false?

推荐答案

$('input[type=file]').change(function() {
    var vals = $(this).val(),
        val = vals.length ? vals.split('\\').pop() : '';
    alert("value changed submit the form here");
    $('input[type=text]').val(val);
});

http://jsfiddle.net/CSvjw/82/

这篇关于jQuery表单上传插件:如何将其减少到一键式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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