JS may be used to dynamically append elements, the data may also be transmitted from the background, of course, there are two ways of thinking,
1. Assemble in the background to return directly;
2. In the foreground JS inside assemble,
If you assemble large amounts of HTML, you may have a single double quotation mark that is prone to problems, so how to solve it? Recently encountered this problem, do a summary.
Can be assembled in a sentence.
Note: HTML element attributes are all enclosed in double-quoted strings with single quotes.
var htmlline= ' <tr id= 'row ' +obj.idarr+ '">";
Htmlline + = ' <td style= "text-align:left;padding-bottom:0px; > ';
Htmlline + = ' <div id="" style= "float:left;" > ';
Htmlline + = ' <div id= 'tdone_b_ ' +obj.idarr+ '"style="float:left">";
Htmlline + = ' <div id= 'img_add_1class= "leftcloseimg" onclick= "group.add_cate (' + obj.idarr+ '></div> ';
Htmlline + = ' </div> ';
Htmlline + = ' <div id="" style= "float:left" > ' + formdata.group_name + ' </div> ';
Htmlline + = ' </div> ';
Htmlline + = ' </td> ';
class= "tal" style= "padding-bottom:0px;text-align:center;" > ' + formdata.sort + ' </td> ';
Htmlline + = ' <td style= "text-align:center;padding-bottom:0px; > ';
class= "childcategory" style= "margin-left:46px;" > ';
Htmlline + = ' <a onclick= 'group.add (\ ' b\ ', ' +obj.idarr+ ')"href="javascript:void (0)"> Add sub-groups </a> ';
Htmlline + = ' <a onclick= 'group.edit (' +obj.idarr+ ')"href="javascript:void (0)"> Modify </a> ‘;
Htmlline + = ' <a onclick= 'group.dele (\ ' delp\ ', ' +obj.idarr+ ')"href="javascript:void (0)"> Delete </a> ';
Htmlline + = ' <a onclick= 'group.useconfirm (1, ' +obj.idarr+ ')"href="javascript:void (0)"> Enabled </a> ';
Htmlline + = ' </div> ';
Htmlline + = ' </td> ';
Htmlline + = ' </tr> ';
Htmlline + = ' <a onclick= ' Group.dele (\ ' delp\ ', ' +obj.idarr+ ') "href=" javascript:void (0) "> Delete </a>";
The onclick function uses a parameter as a string, so the escape character is added
It looks more neat and time-consuming to put together.
Processing character escaping with single double quotation mark in string assembling in JS