js stitching HTML onclick parameter passing

String
1 using & quot;. For example: (& quot; ' + Key + ' & quot;) 
Example:
htmlStr = htmlStr + '<span><img src="'+src+'"/><i onclick="deleteFile(&quot;'+key+'&quot;);" class="fa fa-minus-circle deteleIcon" ></i>&nbsp;'+key+'</span>';

2 使用转义符号 (\''+key+'\')
htmlStr = htmlStr + '<span><img src="'+src+'"/><i onclick="deleteFile(\''+key+'\');" class="fa fa-minus-circle deteleIcon" ></i>&nbsp;'+key+'</span>';

Objects
  3 The object into a string json the JSON.stringify (). But in the conversion process, unexpected end of input error may occur. Change error because the double quotes and double quotes oncilck conflict of json string. Json string needs to be converted into single-quoted strings. 

   Converted into double quotes single quotes the JSON.stringify (Data) .replace ( / \ " / G, " ' ");  

 

Guess you like

Origin www.cnblogs.com/guyuedashu/p/11457218.html