I haven't used js for a long time, so I forgot many things. Recently I encountered a problem when splicing strings with js. No matter how it is spliced, I reported an error in ie, which is very depressing.
After a day, I picked up the code and looked at it. Suddenly I remembered the concatenation of character string escape characters in java, and I remembered that js also had this stuff.
It turns out that:
Copy codeThe Code is as follows:
Tr + = "<td> <a href = 'javascript: void (0); 'onclick = 'confirmdeloneinfo ('" + url2 + "', '" + obj. title + "');'> ";
In the editor, no error is reported. If you click onclick in the browser, no error is reported. After reading the script, the string is completely changed.
After modification:
Copy codeThe Code is as follows:
Tr + = "<td> <a href = 'javascript: void (0); 'onclick = 'confirmdeloneinfo (\" "+ url2 + "\", \ "" + obj. title + "\"); '>
No problem.
Knowledge summary:
The effect of double quotation marks in Javascript is the same, but if your string contains single quotation marks, double quotation marks should be used outside. If your string contains double quotation marks, they should be enclosed in single quotation marks, in this way, no escape characters are needed.
The output result is as follows:
Copy codeThe Code is as follows:
Onclick = 'confirmdeloneinfo ("http ://...? Type = 1 & nodeId = 11 "," Test 1 ");'
It can be seen that in html, if single quotes are used outside, double quotation marks are used. Otherwise, IE reports an error, so Escape Character \ "is used to convert double quotation marks. When dynamically generating html elements, pay special attention to the problem of single double quotation marks. Otherwise, it will be a headache.
A little bit of knowledge, please correct me ....