上传后显示文件 URL - jQuery-文件-上传
Show file URL after upload - jQuery-File-Upload
我尝试了很多,但没有太多关于 JS 的经验。我希望你能帮忙。
我尝试使用查询文件上传 (https://github.com/blueimp/jQuery-File-Upload),它正在运行。我只需要一点定制。
我希望上传图片的文件url在上传后显示。目前只会显示预览图片,linked 到文件 url。
我想我找到了具体的代码,但不知道如何更改它。
on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('<span class="text-danger"/>').text(file.error);
$(data.context.children()[index])
.append('<br>')
.append(error);
}
});
})
我想我需要修改var link = $('')之后的部分。
希望你能帮助我。
TIA
将 $(data.context.children()[index]).wrap(link);
替换为 $("body").append(link);
或者在结果或状态 div 中插入 link,比如说 $("#myDiv").append(link);
我尝试了很多,但没有太多关于 JS 的经验。我希望你能帮忙。
我尝试使用查询文件上传 (https://github.com/blueimp/jQuery-File-Upload),它正在运行。我只需要一点定制。
我希望上传图片的文件url在上传后显示。目前只会显示预览图片,linked 到文件 url。
我想我找到了具体的代码,但不知道如何更改它。
on('fileuploaddone', function (e, data) {
$.each(data.result.files, function (index, file) {
if (file.url) {
var link = $('<a>')
.attr('target', '_blank')
.prop('href', file.url);
$(data.context.children()[index])
.wrap(link);
} else if (file.error) {
var error = $('<span class="text-danger"/>').text(file.error);
$(data.context.children()[index])
.append('<br>')
.append(error);
}
});
})
我想我需要修改var link = $('')之后的部分。
希望你能帮助我。
TIA
将 $(data.context.children()[index]).wrap(link);
替换为 $("body").append(link);
或者在结果或状态 div 中插入 link,比如说 $("#myDiv").append(link);