简体   繁体   English

在chrome中缓存dom元素

[英]caching dom elements in chrome

i created a module for uploading contents. 我创建了一个用于上传内容的模块。 it is basically done by file api. 它基本上是由文件api完成的。

the html code is 的HTML代码是

    <input type="file" id="filepicker-input" multiple="true" style="display:none;"/>  
    <div class="addfile_btndiv" id="addfile_btndiv">
    <span id="direct-upload-text"><input name=""  class="add_filebtn" type="button" value="Add Files" /></span>
    </div>
    <div id="dropped-files">

    </div>

    <div class="clear"></div>
    </div>

the operation is taken place when onchange the file. 在更改文件时进行该操作。 the js code is js代码是

 var fileInput  = document.getElementById("filepicker-input");
 document.getElementById("direct-upload-text").onclick = function(e){
    fileInput.click();
 }
 fileInput.onchange = function(e) {

//basically same as in ondrop
    $("#dropped-files").html("");

    var files = e.target.files;

    var type            = 'zip';
    var location_block  = 1;
    var check = createPreviewElements(files, type, location_block);

    if(check){

        //add an onclick property to the upload button, this will trigger the main upload process
        var uploadButton    = document.getElementById('upload_button_zip_1');

        uploadButton.onclick = function(e){
            var block   = document.getElementById("current_block");
            block.value = location_block;
            uploadButton.onclick = null; //disable the onclick event once it happened
            document.getElementById('loading_wrapper').style.display = 'inline';
            setTimeout(function(){$('#loading_wrapper').fadeOut()}, 6000);  //fade out loader after 2 sec
            startupload(files, type, location_block);
        };
    }


} 

the uploading is working perfectly. 上传工作正常。 my problem is that there is a cancel button present for this uploading. 我的问题是此上传文件存在取消按钮。 i managed this by some javascript code but after when the user can reselect the same file then 'onchange' will not trigger. 我通过一些JavaScript代码对此进行了管理,但是当用户可以重新选择相同文件后,“ onchange”将不会触发。 so i add a new logic in cancel button that remove the current input type and place a new input type. 所以我在取消按钮中添加了一个新逻辑,以删除当前输入类型并放置一个新输入类型。 the code is 该代码是

            $('#filepicker-input').attr("id", "newID");
    var foo     = document.getElementById("blk_switchbox1");
    var olddiv  = document.getElementById("newID");
    foo.removeChild(olddiv);
    var element = document.createElement("input");

    element.setAttribute("type", "file");
    element.setAttribute("id", "filepicker-input");
    element.setAttribute("class", "nodisplay");


    foo.appendChild(element);

this working fine in mozila. 这在莫济拉运作良好。 but not in chrome. 但不是铬。 in chrome there is any cashing present for dom elements. 在chrome中,dom元素有任何兑现。 please help me 请帮我

Have you tried triggering the change event manually? 您是否尝试过手动触发更改事件? Rather than its click event? 而非点击事件?

document.getElementById("direct-upload-text").onclick = function(e){
    if(fileInput.value != '') {
        fileInput.change();
    } else {
        fileInput.click();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM