2012-05-09 86 views

回答

2

的圖像創建佔位符:

<ul id="sortable"></ul> 

綁定排序的佔位符:

$("#sortable").sortable(); 
$("#sortable").disableSelection(); 

綁定該ondrop功能佔位符:

$('#sortable').on(
    'drop', 
    function(e){ 
     if(e.originalEvent.dataTransfer){ 
      if(e.originalEvent.dataTransfer.files.length) { 
       e.preventDefault(); 
       e.stopPropagation(); 
       upload(e.originalEvent.dataTransfer.files); 
      } 
     } 
    } 
); 

最後但並非最不重要的,寫文件API部分:

function upload(files){ 
    for (var i = 0, f; f = files[i]; i++) { 
     var imageReader = new FileReader(); 
     imageReader.onload = (function(aFile) { 
      return function(e) { 
       var li = document.createElement('li'); 
       li.innerHTML = ['<img class="images" src="', e.target.result,'" title="', aFile.name, '"/>'].join(''); 
       $('#sortable').append(li); 
     }; 
    })(f); 
    imageReader.readAsDataURL(f); 
} 

見行動全碼在: http://jsfiddle.net/xKYxL/2/

現金 https://www.ibm.com/developerworks/mydeveloperworks/blogs/bobleah/entry/html5_code_example_of_file_api_drag_drop_hard_drive_files_to_a_webpage28?lang=en