Article From:https://www.cnblogs.com/xuchao0506/p/9970246.html

Simple Description: In the process of development, we often do some splicing operation in js. At the same time, we will inevitably encounter the splicing between tags and function parameters, using single quotation marks, double quotation marks or even escape characters. This kind of problem makes the first two big, and debugging is simply a problem.Anti-human!!!

The code directly pasted together should be marked with color.

//The code makeId () is a random string method
var strItem = [[${contractObj.attachmentsPath}]];
var myArray=new Array();
myArray = strItem.split(",");
var idSet = [];
for(var i=0; i<myArray.length;i++){
var str = "img"+ makeId();
var html = ' <img th:src="" class="imgTofile" id="'+ str +'" value="'+myArray[i]+'" onclick="deleteImg('+ str +')" width="35px" height="35px"/>';
idSet.push(str);
$("#imgDiv").append(html);
} 

 

Summary: I believe that from now on I will encounter the problem of splicing pages will not be so big!!!

Leave a Reply

Your email address will not be published. Required fields are marked *