清除上传的本地对象功能?

时间:2014-02-27 07:27:36

标签: javascript jquery

http://jsfiddle.net/QC76K/

  // Closure to capture the file information.
  reader.onload = (function(theFile) {
    return function(e) {
      // Render thumbnail.
      var span = document.createElement('span');
      span.innerHTML = ['<img class="thumb" src="', e.target.result,
                        '" title="', escape(theFile.name), '"/>'].join('');
      document.getElementById('list' + filesId).insertBefore(span, null);
    };
  })(f);

我想在此脚本中添加“全部清除”按钮。我使用html(“”)来清空笔记。我还是无法重新上传照片。它存放在哪里?以及如何清除它?

2 个答案:

答案 0 :(得分:0)

只需添加此

即可
function clearAll() {
    document.getElementById('list').innerHTML='';
    document.getElementById('files').value=''; 
}

工作小提琴http://jsfiddle.net/sajith/Tk4XE/1/

答案 1 :(得分:0)

我认为这就是你想要的:http://jsfiddle.net/jogesh_pi/QC76K/2/

// Add Clear Button in HTML Section
<button id="clear">Clearall</button>

document.getElementById('clear').addEventListener('click', clearall, false);

function clearall(){
    var list = document.getElementById('list');
    var files = document.getElementById('files');

    list.innerHTML = "";
    files.value = "";
}