JQuery 将一个 Div 值的百分比添加到另一个值

JQuery Adding the percentage of a Div value to another

本文关键字:百分比 添加 另一个 Div 一个 JQuery      更新时间:2023-09-26

使用JQuery,我正在尝试设置div的id值的百分比并将其写入另一个div。

这是我当前的代码...

  $("#percentage").text(
    parseFloat($("#total").text(percentage calculation here?))
    );

因此,如果 #capacity 的值为 100,#total 的值为 10,则 #percentage 的值将为 10

我怎样才能得到这个结果?

希望这是有道理的

$("#percentage").text(function() {
    var result = (parseInt($("#capacity").text(), 10) / parseInt($("#total").text(), 10));
    if (!isFinite(result)) result = 0;
    return result;
});​

小提琴