当我尝试在div
内加载一个模板页面时,我遇到了jQuery的问题。我试图使用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/>
答案 0 :(得分:0)
使用点击事件进行一次模板上传
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); }); });