私はお湯を発明しようとしています:D。私はhtml5Uploaderを使用していますが、すべてが正常に機能しています(画像はエラーなしでアップロードされています)。この部分では、問題は少し遅れて発生します。
onServerLoad: function(e, file) {
$('.img_upload').on('click', function() {
$('#text').val($('#text').val() + $(this).attr('title'));
});
}
値はテキストエリアに追加されていますが、アップロードされた画像があるため、何度も追加されます(たとえば、first.pngという名前の画像が5つある場合、テキストエリアにfirst.pngが5回追加 されます)。どうすればこれを回避できますか?
$(function() {
var fileTemplate = "<div id=\"{{id}}\">";
fileTemplate += "<div class=\"preview\"></div>";
fileTemplate += "<div class=\"filename\">{{filename}}</div>";
fileTemplate += "</div>";
function slugify(text) {
text = text.replace(/[^-a-zA-Z0-9,&\s]+/ig, '');
text = text.replace(/-/gi, "_");
text = text.replace(/\s/gi, "-");
return text;
}
$("#dropbox").html5Uploader({
onClientLoadStart: function(e, file) {
var upload = $("#upload");
if (upload.is(":hidden")) {
upload.show();
}
upload.append(fileTemplate.replace(/{{id}}/g, slugify(file.name)).replace(/{{filename}}/g, file.name));
},
onClientLoad: function(e, file) {
$("#" + slugify(file.name)).find(".preview").append("<img class=img_upload title=\"" + file.name + "\" src=\"" + e.target.result + "\" alt=\"\">");
},
onServerLoad: function(e, file) {
$('.img_upload').on('click', function() {
$('#text').val($('#text').val() + $(this).attr('title'));
});
}
});
});