HTML5页面元素中的文本最快速替换replace()方法

$.ajax({
type:"get",
url:spanUrl,
dataType:'jsonp',
jsonpCallback:'jsonp',//jsonp数据,需要数据库提供这个jsonp格式
success:function(selDate){
var htmlStr1 = '<a href="details.html?serialNumber={id}" class="item">'+
'<img src="{picUrl}" alt="" class="pic">'+
'<p>'+
'<strong>{model} {title}</strong>'+
'</p>'+
'<img src="images/btn-detail.png" alt="" class="detail"></a>',
arr1 = [];
if(selDate.length==0){
$(".noData").css('display','block');
}else{
console.log(selDate)
for(var i=0;i<selDate.length;i++){
var o=selDate[i],
t=htmlStr1.replace('{id}', o.serialNumber)
.replace('{picUrl}', o.categoryimageOn)
.replace('{model}', o.model)
.replace('{title}',o.productFamily);
arr1.push(t);
}
$("#part1").html(arr1.join(''))
}
}

})
原文地址:https://www.cnblogs.com/pengchengzhong/p/6401725.html