The solution of the error of JS string stitching in IE

Source: Internet
Author: User

  Recently used JS stitching string encountered problems, no matter how the stitching in IE in the error, so found a good solution, here with you to share the following

Long time no JS, a lot of things have forgotten. The recent use of JS stitching string encountered problems, no matter how the stitching in IE in the error, very depressed.     After a day, and picked up the code to look at, suddenly remembered in Java stitching string escape characters, just think of JS also have this dongdong.     It turns out this:    code is as follows: TR = "<td><a href= ' javascript:void (0); ' onclick= ' Confirmdeloneinfo ('" + url2+ "', '" "+obj.title+"); ' ><img src= ' images/tab/010.gif '/> ';    in the editor is not an error, to the browser how to point the onclick are not reflected, F12 the error, looked at the script, the string completely changed     modified:    code as follows: TR = "<td><a href= ' javascript:void (0); ' onclick= ' Confirmdeloneinfo (" "+ url2+ "", "" +obj.title+ ""); ' ><img src= ' images/tab/010.gif '/> '     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 use double quotes outside, and if you have double quotes in your string, the outside is enclosed in single quotes, so you don't have to escape characters.     The output above is:    code as follows: Onclick= ' Confirmdeloneinfo ("http://...?type=1&nodeId=11", "Test 1"); '     See in HTML, if the outside use of single quotes inside to use double quotes, otherwise IE error, so use the escape character "convert double quotes." In the dynamic generation of HTML elements, pay particular attention to the issue of single double quotes, otherwise it will be a headache.     Oh, a little knowledge of the summary, welcome correction ....   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.