相关疑难解决方法(0)

选择同一文件时不会触发HTML输入文件选择事件

有没有机会检测用户为input类型file元素的HTML所做的每个文件选择?

之前曾多次询问此问题,但onchange如果用户再次选择同一文件,则通常建议的事件不会触发.

html javascript forms dom-events

181
推荐指数
5
解决办法
13万
查看次数

Chrome文件上传错误:更改事件不会使用同一文件执行两次

我正在处理这个html5文件上传器插件,但它有一个谷歌Chrome的错误,我无法理解和解决它.它适用于Firefox.

jsfiddle链接

问题是您无法从桌面上载两次相同的文件.

当您第一次单击,选择,然后单击确定以从桌面上载文件时,它应该警告消息,例如'.button-1' - 取决于您单击的上载按钮.

然后,如果您再次尝试上传相同的文件,则不再执行此行代码,

$(".upload-file",object_parent).change(function() {

             ...
             ...

             alert($cm.selector);

});
Run Code Online (Sandbox Code Playgroud)

知道这个插件出了什么问题吗?

(function($){

    // Attach this new method to jQuery
    $.fn.extend({ 

        // This is where you write your plugin's name
        upload_file_html5: function(options) {

            // Set the default values, use comma to separate the settings, example:
            var defaults = {
                objectSuperparent:    '.media'
            }

            var options =  $.extend(defaults, options);
            var o = options;

            var $cm = this.click(function(e){

                // <a> button is the …
Run Code Online (Sandbox Code Playgroud)

jquery html5 google-chrome file-upload onchange

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

HTML输入文件onchange不会再次触发其他文件

我已经看到许多有关输入文件元素onchange第二次不触发同一文件事件的问题,但我的情况并非如此。选择其他文件时,我的onchange处理程序未触发

我选择了一个文件,然后,如果我尝试选择另一个文件,它将无法正常工作。出现文件选择对话框,我选择了(不同的)文件,仅此而已。onchange第一次调用的处理程序不再被调用。选择文件后什么都没有发生。

这是我的JS:

<input type="file" id="my-input" name="my-input" class="hidden" />

(在jQuery上): $("#my-input")[0].onchange = onSelectedFileChange;

function onSelectedFileChange(e) {
    file = e.target.files[0];
    handleFile(); //my code that processes the file, has nothing to do with the input element.
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过重新添加onchangein handleFile方法(例如,复制$("#my-input")[0].onchange = onSelectedFileChange;到其中),但是它似乎也不起作用。选择文件后,输入法的onchange属性设置为null,即使我再次显式设置它,它也仍然保持null。

为什么会这样呢?这恰好是跨浏览器的情况。

更新:这是handleFile方法:

//file is in the global scope, from the previous method
function handleFile() {
    var lowerName = file.name.toLowerCase();
    if …
Run Code Online (Sandbox Code Playgroud)

html javascript file-upload html-input

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