I haven't used js for a long time, and I have forgotten a lot of things. I have encountered problems when splicing strings with js recently. No matter how they splice them, they will report errors in ie, which is very depressing.
One day later, I picked up the code and looked at it. I suddenly remembered the fact that I spliced string escape characters in Java, and then I remembered that js also had this thing.
So that's it:
The code copy is as follows:
tr += "<td><a href='javascript:void(0);' onclick='confirmDelOneInfo('"+url2+"','"+obj.title+"');'><img src='images : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : /tab/010.gif'///>";
There is no error in the editor, and no error in the browser is reported when clicking onclick. F12 reports an error. After reading the script, the string completely changed
After modification:
The code copy is as follows:
tr += "<td><a href='javascript:void(0);' onclick='confirmDelOneInfo(/""+url2+"/",/""+obj.title+"/");'><img src='images/tab/010.gif'/>"
That's no problem.
Knowledge summary:
The effect of single and double quotes in js is the same, but if you have single quotes in your string, you should use double quotes outside. If you have double quotes in your string, you should use single quotes outside, so you don't need to Escape characters.
The above output is:
The code copy is as follows:
onclick='confirmDelOneInfo("http://...?type=1&nodeId=11","test1");'
It can be seen that in html, if single quotes are used outside, double quotes should be used inside, otherwise IE will report an error, so escape characters / "convert double quotes. When dynamically generating elements of html, pay special attention to the problem of single and double quotes. , otherwise it will be a headache.
Haha, a summary of some little knowledge is welcome to correct me...