相关疑难解决方法(0)

清除Internet Explorer中的文件输入框

我的页面上有一个文件上传框和一个清除按钮.当我按下清除按钮时,我希望清除文件上传框中的文本.

以下适用于Firefox,但不适用于IE(文本保留在那里).这有解决方法吗?

$("#clear").click( function() {
    $("#attachment").val("");
    //document.myform.attachment.value = "";
})
Run Code Online (Sandbox Code Playgroud)

HTML:

<form name="myform">
    <input type="file" name="attachment" id="attachment" />
</form>
<br /><button id="clear">Clear Attachment</button>
Run Code Online (Sandbox Code Playgroud)

的jsfiddle

html javascript jquery internet-explorer file-upload

16
推荐指数
3
解决办法
3万
查看次数

如何重置(清除)文件输入

我怎样才能在IE中重置文件输入,我使用了以下内容,它在chrome和FF中工作,但不是IE

fileInputElement.value=""

IE中的替代品是什么?

javascript file-io internet-explorer cross-browser

15
推荐指数
3
解决办法
2万
查看次数

替换<input type ='file'/>中的onchange事件

看起来真的很简单,但无法弄清楚.我一直在元素上使用onchange事件,它运行良好.一旦用户浏览并选择了一个文件,我就会获得路径并使用我的自定义js函数上传它.

问题是,如果用户连续两次选择相同的文件,这不起作用,onchange不会触发(这是有道理的,因为没有任何改变)但在我的情况下,对我来说捕获该事件也很重要,得到路径和上传.

编辑

(类似于使用jQuery清除<input type ='file'/>,不确定我是否应该将其解析为重复)

html javascript file-upload file javascript-events

14
推荐指数
1
解决办法
4万
查看次数

如何从HTML5 FileReader中的"输入类型"清除以前的文件

我有一个文件输入:

<img id="uploadPreview">
   <div id="changeImage">Change</div>
<div id="customImage">
   <input type="file" id="myfile" multiple style="display:none" onchange="PreviewImage();" />
   <div class='upload blank' id="add-image"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

功能如下:

var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("myfile").files[0]);

oFReader.onload = function (oFREvent) {
    document.getElementById("uploadPreview").src = oFREvent.target.result;
};

function PreviewImage() {
        var oFReader = new FileReader();
        oFReader.readAsDataURL(document.getElementById("myfile").files[0]);
        $("#uploadPreview").removeClass('hide'); //for manipulating something in the dom
        $('#changeImage').removeClass('hide'); //for manipulating something in the dom
        $("#customImage").addClass('hide'); //these are for manipulating something in the dom

        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview").src = oFREvent.target.result;
        };
    };
Run Code Online (Sandbox Code Playgroud)

一切都很完美.现在我有一个更改按钮.我希望如果有人点击它,那么之前上传的文件细节就会消失.功能如下所示:

$('#changeImage').click(function(){
  $('#uploadPreview').addClass('hide'); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5 filereader

12
推荐指数
2
解决办法
2万
查看次数

无法使用JQuery-File-Upload从文件列表中删除文件

我有一个使用JQuery-File-Upload插件的问题.我直接使用插件而不是通过作者提供的html示例页面.基本上我有一个带有一些输入的表单,其中一个是文件输入.第一次上传工作正常,但是当我尝试第二次上传时,两个文件都被发送(第一次是第一次),而它应该只是第二次上传.

例:

  • 选择文件1.
  • 文件1已上传.
  • 成功.
  • 使用jquery我用$(FORM_SELECTOR).trigger('reset')重置表单
  • 选择文件2.
  • 文件1和文件2已全部上传.
  • 问题.

现在我有两份文件1.这不是我想要的.

显然使用ajax表单上传没有多大意义,如果它只运行一次,所以我认为有一些我缺少的东西.

有没有办法重置文件队列?

检查data.files对象时,我可以看到表单重置后文件就在那里.我该怎么做才能将插件与输入同步或清除data.files.如果我手动清除data.files数组(通过pop或data.files = []),尝试第二次上传不起作用.

我初始化上传表单如下:

    $('#file-upload-form').fileupload({
    url: 'uploads/upload',
    type: 'POST',
    dataType: 'json',
    multipart: true,
    dropZone: null,
    formAcceptCharset: 'utf-8',
    autoUpload: true,
    add: function (e, data) {
        fileUploadData = data;
        $("#upload-file-btn").click(function () {
            data.submit()
                .success(function (e, status, data) {
                    console.log("success response from post", status, data);
                    var i = '<input id="file-select-input" name="files[]" multiple/>';
                    $('#file-select-input').replaceWith(i);
                })
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

javascript ajax file-upload jquery-plugins jquery-file-upload

7
推荐指数
1
解决办法
1万
查看次数

如何只清除文件上传字段?

这是JSfiddle:http://jsfiddle.net/buyC9/128/

我想清除时只清除文件上传字段.

我的HTML:

<h1>Upload image:</h1>
<input type="file" name="blog[opload]" id="blog_opload" class="imagec">
<input type="url" size="50" name="blog[url]" id="blog_url" class="imagec">
<div id="preview">
</div>
Run Code Online (Sandbox Code Playgroud)

我的Jquery:

$('input').change(function() {
    var el = $(this);
    if (this.value === "") {
        $('.imagec').prop('disabled', false);
        this.disabled = false;
        $('#preview').hide();
    } else {
        $('.imagec').prop('disabled', true);
        el.prop('disabled', false);
        alert(el.val());
        if (el.attr('type') == 'url') {
            $('#preview').show().html('<img src=' + '"' + el.val() + '"' + ' />');
        }
    }
});

function reset_html(id) {
    $('.' + id).html( $('.' + id).html() );
}

var imagec_index …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

5
推荐指数
2
解决办法
1万
查看次数

无法在javascript jquery中清除input type = file

可能重复:
使用jQuery清除<input type ='file'/>

这是我的代码:

 <input ID="fileUpload1" runat="server" type="file" style="width:275px; position:absolute; left:1px"/>
Run Code Online (Sandbox Code Playgroud)

我尝试了一些解决方案:

$("input[type='file']").val('');
$('#DivfileUpload').replaceWith("<input class=VWButton ID=fileUpload1 runat=server type=file style=width:275px; position:absolute; left:1px/>");
Run Code Online (Sandbox Code Playgroud)

和许多其他人从网上但没有成功.

javascript asp.net jquery input

5
推荐指数
2
解决办法
1万
查看次数

上传期间的文件上传进度

我在文件上传进度方面遇到了一些问题.我在xampp,windows 7上使用zend framework 2.2.

表格(SignupForm):

namespace Application\Form;

 use Zend\Form\Form;
 use Zend\Form\Element;

 class SignupForm extends Form
 {  
     public function __construct($name = null)
     {
        $this->add(array(
            'name' => 'username',
            'type' => 'Text',
            'options' => array(
                'label' => 'Username',
                'label_attributes' => array(
                    'class' => 'formlabel',
                ),
            ),
        ));
                      $this->add(array(
            'type' => 'Zend\Form\Element\File',
            'name' => 'fileupload',
            'attributes' => array(
                'id' => 'fileupload',
            ),
            'options' => array(
                'label' => 'Photo',
                'label_attributes' => array(
                    'class' => 'formlabel',
                ),
            ),
        ));
     }
 }
Run Code Online (Sandbox Code Playgroud)

Controller(IndexController):

<?php

namespace Application\Controller;

use …
Run Code Online (Sandbox Code Playgroud)

php zend-framework2

5
推荐指数
1
解决办法
2268
查看次数

如何"取消选择"所选文件?

我正在使用它来允许用户选择并上传文件:

<input id="fileInput" type="file" ng-file-select="onFileSelect($files)">
Run Code Online (Sandbox Code Playgroud)

这正确显示:

在此输入图像描述

当用户点击"上传"时,我会上传该文件.

当用户单击"删除"时,如何清除文件名?

angularjs angular-file-upload

5
推荐指数
2
解决办法
6951
查看次数

输入文件-如果未更改,请保留以前的文件

当用户单击input['type="file"']并选择一个文件...时,将附加文件。但是,如果用户再次单击输入并浏览文件,但没有选择一个并关闭对话框,则所选文件消失(输入字段重置)。有什么办法可以防止这种情况?

html javascript jquery

5
推荐指数
1
解决办法
1549
查看次数