我正在創建一個設置2個屬性的頁面,然後我試圖在頁面加載後引用這些屬性。jQuery設置屬性,然後獲取屬性
我已經能夠設置沒有問題的屬性,如果我將它們硬編碼到信用卡和借記卡屬性中,我也能夠引用這些屬性。
但試圖動態調用它們不起作用。接受建議。
<div class="net" credit="" debit=""></div>
$(document).ready(function() {
... some fancy code involving arrays and junk ...
if(TYPE == 'credit') {
$(".net").attr('credit',data.response.stats.total);
} else if (TYPE = 'debit') {
$(".net").attr('debit',data.response.stats.total);
}
});
$(window).bind("load", function() {
afterPageLoad();
});
function afterPageLoad(){
total_credit = $(".net").attr('credit');
total_debit = $(".net").attr('debit');
total = (total_credit - total_debit);
$(".net").html("$"+total);
}
看起來好像沒什麼問題http://jsfiddle.net/arunpjohny/8m3Gh/1/雖然我會建議使用'。數據()' –
在您的瀏覽器控制檯 –
任何錯誤你應該使用'parseFloat();'當獲取信用和借記的屬性 –