Jquery加载多个模板页面

Jquery load multiple template pages

本文关键字:加载 Jquery      更新时间:2023-09-26

我有一个问题与jQuery当我试图加载几个一个模板页面内的div。我试图用jQuery选择器替换模板中的数据。我需要使用jQuery选择器让currency()工作。只保留最后插入的数据

代码如下:

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/>

使用click event for one template upload

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); }); });