Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 最初未选择我的pdf文件,仅在internet explorer中选择_Javascript_Jquery_Html_Internet Explorer - Fatal编程技术网

Javascript 最初未选择我的pdf文件,仅在internet explorer中选择

Javascript 最初未选择我的pdf文件,仅在internet explorer中选择,javascript,jquery,html,internet-explorer,Javascript,Jquery,Html,Internet Explorer,我有一个输入文件来选择PDF。选择pdf后,会打开文本框,为每个pdf提供标题 在谷歌浏览器中,一切都正常工作 在InternetExplorer中,我遇到了一个问题,我无法找出原因和解决方法 我的问题是: 在internet explorer中,当我第一次选择pdf时,不会发生任何事情,pdf不会被选中 我需要选择其他pdf,但不能是第一个选择的pdf,当我选择其他pdf时,它可以工作 然后开始工作总是很好,但我第一次选择pdf时总是有这个错误 您可以在这里看到我的问题的完整示例:但要查看我的

我有一个输入文件来选择PDF。选择pdf后,会打开文本框,为每个pdf提供标题

在谷歌浏览器中,一切都正常工作

在InternetExplorer中,我遇到了一个问题,我无法找出原因和解决方法

我的问题是:

在internet explorer中,当我第一次选择pdf时,不会发生任何事情,pdf不会被选中

我需要选择其他pdf,但不能是第一个选择的pdf,当我选择其他pdf时,它可以工作

然后开始工作总是很好,但我第一次选择pdf时总是有这个错误

您可以在这里看到我的问题的完整示例:但要查看我的问题,您需要在internet explorer中进行测试

我的Html:

我的jQuery:


您的jquery代码有一些错误。我目前找不到IE的解决方案,但即使在chrome和firefox中,这段代码也会从第二次上传pdf两次。我已经修改了jquery以使其正常工作

$('.j_gsendp').click(function(){
    $('.j_galleryp').trigger('click');
});

$('.j_galleryp').change(function () {
    update();    
});

function update(){
    var input = $('.j_galleryp')[0];
    var allFiles = input.files;
    var numFiles = input.files.length;
    alert(numFiles);
    $('.j_gfalsep').animate({
        width: '400'
    }, 500, function () {
        $(this).html('You select <strong>' + numFiles + '</strong>files.');
        for (var i = 0; i < numFiles; i++) {
            var file = allFiles[i],
                name = file.name;
            $('#test').append('<span class="field">Title of pdf ' + name + ':</span><input type="text" name="title[]" value="' + name + '"/><br><br>');
        }
    });
}
使用此jquery代码,不要将事件处理程序绑定到其他事件处理程序中。您可能会多次绑定同一事件


注意:我无法编辑此问题,因此我将此作为解决方案来回答。

无需为将此作为解决方案而不是编辑来发布而道歉。您的代码就是解决方案!非常感谢您的Akash K。我一直在考虑这个错误,但不知道如何解决它。您的解决方案非常有效!很高兴这奏效了。没有在IE中进行测试,所以不确定这是否有效是的,它正在工作。这是我做的第一件事:
$('.j_gsendp').click(function(){
    $('.j_galleryp').click().change(function(){
         var allFiles = this.files;  
         var numFiles = this.files.length;

        $('.j_gfalsep').animate({width:'500'}, 500, function(){
            $(this).html('You selected<strong>'+ numFiles +'</strong> files.'); 

            for(var i = 0; i<numFiles; i++) {
                var file = allFiles[i],
                    name = file.name;
                $('#test').append('<div class="message">Give a title to pdf <strong>'+name+':</strong></div><span>Title for pdf '+name+':</span><input type="text" name="title[]" value=""/><br><br>');
             } 
            });
              this.val('');
        });
    });
});
$('.j_gsendp').click(function(){
    $('.j_galleryp').trigger('click');
});

$('.j_galleryp').change(function () {
    update();    
});

function update(){
    var input = $('.j_galleryp')[0];
    var allFiles = input.files;
    var numFiles = input.files.length;
    alert(numFiles);
    $('.j_gfalsep').animate({
        width: '400'
    }, 500, function () {
        $(this).html('You select <strong>' + numFiles + '</strong>files.');
        for (var i = 0; i < numFiles; i++) {
            var file = allFiles[i],
                name = file.name;
            $('#test').append('<span class="field">Title of pdf ' + name + ':</span><input type="text" name="title[]" value="' + name + '"/><br><br>');
        }
    });
}