As shown below:
function(msgArr) { var len = msgArr.length; var n = 0 ; var htmlSpan = ""; for (var j = 0; j < len - 1; j++) { htmlSpan += '<span>・</span>'; } htmlSpan += '<span>・</span>'; var imgs = []; var img = []; img[0] = '<a href="' + ctx + '/webservice/dish/detail?id='; img[1] = '#'; img[2] = '"><img src="'; img[3] = '#'; img[4] = '"></a>'; for (var i = 0; i < len; i++) { img[1] = msgArr[i].id; img[3] = msgArr[i].pic; imgs.push(img.join("")); } $("#banner_list").html(imgs.join("")); $(".dots").html(htmlSpan);}The above code is taken from a script I wrote recently. In this function, it just reflects two types of js splicing strings to add new elements to the DOM. The first method is to add directly, the second method is to use the join() method of the array for splicing, and the second method is to be more efficient.
The above two simple methods of splicing strings (must read) of JS are all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.