我們如何可以強制返回圖像類型(如果萬一它不返回),同時使用readAsDataURL讀取圖像,readAsDataURL沒有返回圖像類型
window.onload = function() {
if (window.File && window.FileList && window.FileReader) {
$("#file").on("change", function(event) {
event.preventDefault();
var output = document.getElementById("result");
existingNode = document.getElementById("addMore");
var files = event.target.files;
for (var i = 0; i < files.length; i++)
{
var file = files[i];
var picReader = new FileReader();
picReader.onload = function(event) {
var picFile = event.target;
var formElement = document.getElementById("submitForm");
var dataToBeSent = new FormData(formElement);
count++;
var div = document.createElement("div");
div.innerHTML = '<div class="fl pu_mr1 pu_mr2 wrap' + count + '">' + '<div class="photobox posrel">' + '<div class="posabs txtc fontlig color2 f14 lh30 pum35 dispnone retryMessage"><i class="up_sprite pu_retry pu_mt2"></i>Retry</div>' + "<img class='classimg1 opa50 uploading" + count + "' src='" + picFile.result + "'" + "title='" + picFile.name + "'/>" + '<div class="posabs pu_pos1" onclick="deleteThisPhoto(' + count + ')"><a href="#" class="up_sprite pu_cross"></a></div>' + '<div class="posabs fullwid pu_pos2 uploadingBar' + count + '">' + '<div class="wid80p brdr12">' + '<div class="bg7 hgt10 mrl0 uploadingPercent' + count + '" style="width:0px;"></div>' + '</div></div></div></div>';
output.insertBefore(div, existingNode);
generatingDiv.innerHTML = "";
formDataArray[count] = dataToBeSent;
};
picReader.readAsDataURL(file); //Read the image
}
如果可能的話,可以張貼'js'?謝謝 – guest271314 2014-12-05 06:24:07