2014-05-14 111 views
0

當我嘗試加載div中的幾個模板頁面時,我遇到了jQuery問題。我試圖用jQuery選擇器替換模板中的數據。我需要使用jQuery選擇器來使currency()工作。只有我插入的最後一個數據應該保留。Jquery加載多個模板頁面

下面的代碼:

HTML:

<div id="loanPH"></div> 

的Javascript:

//This iterate through the banks to a person that can be several which 
//becomes the issue 
$.each(person.bank, function(index, element) { 
    $('#loanPH').append($("<div>").load('/Templates/MinSide/loanView.html', null, function() { 
     //To be able to use currency it got to be a jQuery object and 
     //not a simple string that I could have appended 
     $('#total').html(element.total).currency(); 
     $('#rate').html(element.rate).currency(); 
     $('#bankName').html(element.bankName); 
    })); 
}); 

模板loanView.html:

Total: <span id="total"></span><br/> 
Rate: <span id="rate"></span><br/> 
Bank: <span id="bankName"></span><br/> 

回答

0

使用Click事件一個模板上傳

window.jQuery.click(person.bank, function (index, element) { $('#loanPH').load('/Templates/loanView.html', null, function() { //To be able to use currency it got to be a jQuery object and //not a simple string that I could have appended $('#total').html(element.total).currency(); $('#rate').html(element.rate).currency(); $('#bankName').html(element.bankName); }); });

+0

感謝您的答覆。 person.bank是一個我需要通過使用.each完成的for循環遍歷的數組,所以我相信click事件不會起作用 –