我在 magento 中使用 dropzone.js 上传文件。进度条工作正常,但我也想显示进度百分比。以下函数正在为跨度添加样式。
uploadprogress: function(a, b) {
var c, d, e, f, g;
if (a.previewElement) {
for (f = a.previewElement.querySelectorAll("[data-dz-uploadprogress]"), g = [], d = 0, e = f.length; e > d; d++) c = f[d], g.push("PROGRESS" === c.nodeName ? c.value = b : c.style.width = "" + b + "%");
return g
}
},
在下面的 html 中添加了 style="width:xx%"。
我还想将上面代码中 g 返回的 % 结果显示为文本,以便用户也可以看到数字。
最佳答案
假设您的进度条中有一个跨度,例如:
<div class="progress">
<div class="progress-bar progress-bar-primary" role="progressbar" data-dz-uploadprogress>
<span class="progress-text"></span>
</div>
</div>
您应该按如下方式定义您的上传进度函数:
uploadprogress: function(file, progress, bytesSent) {
if (file.previewElement) {
var progressElement = file.previewElement.querySelector("[data-dz-uploadprogress]");
progressElement.style.width = progress + "%";
progressElement.querySelector(".progress-text").textContent = progress + "%";
}
}
关于javascript - 如何在 dropzone.js 中显示上传进度百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38620641/