使用JQuery,我試圖設置div的id值的百分比並將其寫入另一個div。JQuery將Div值的百分比添加到另一個
這裏是我當前的代碼...
$("#percentage").text(
parseFloat($("#total").text(percentage calculation here?))
);
所以,如果#capacity有值100和#合計有10個數值則#percentage的價值將是10
我怎樣才能得到這個結果?
希望這是有道理
使用JQuery,我試圖設置div的id值的百分比並將其寫入另一個div。JQuery將Div值的百分比添加到另一個
這裏是我當前的代碼...
$("#percentage").text(
parseFloat($("#total").text(percentage calculation here?))
);
所以,如果#capacity有值100和#合計有10個數值則#percentage的價值將是10
我怎樣才能得到這個結果?
希望這是有道理
$("#percentage").text(function() {
var result = (parseInt($("#capacity").text(), 10)/parseInt($("#total").text(), 10));
if (!isFinite(result)) result = 0;
return result;
});
當你說'div的ID value'你的意思''
是的,這是正確的 – Satch3000 2012-08-15 17:54:44