In JavaScript, improper use of single quotes and double quotes may result in js Code conflicts and JavaScript cannot run correctly. It is easy to resolve the conflict between single quotes and double quotes in JavaScript, we only need to use single-and-double-mixing, and we can escape all.
To solve the single-cited and double-cited conflicts in js, consider the following code:
The Code is as follows: |
Copy code |
Html + = '<a onclick = "return removeOpenCss (' + e. point. lng + e. point. lat + ')"> cancel </a> '; |
This is the code in js. If you write this code here, a js error will be prompted because the parameters in the removeOpenCss method do not have single or double quotes. If you write this code here:
The Code is as follows: |
Copy code |
Html + = '<a onclick = "return removeOpenCss ("' + e. point. lng + e. point. lat + '")"> cancel </a> '; |
An error is reported directly, because the single cited and double cited conflicts here, so I only solve this problem through:
The Code is as follows: |
Copy code |
Html + = '<a onclick = "return removeOpenCss (& quot;' + e. point. lng + e. point. lat + '& quot;) "> cancel </a> '; |
In JavaScript, an error occurs when two double quotation marks are nested.
The following solutions are available:
Replace the inner single quotes'
Replace double quotation marks with & quot;
The following is an example.
The Code is as follows: |
Copy code |
<Html> <Head> <Title> Javascript single quotes </Title> <Script> Function showmSG (S) { Alert (S ); } </Script> </Head> <Body> <Input type = "button" value = "Click Me" onclick = "showmSG ('' & quot; FSDFDS ') "/> <Input type = "text" id = "txtName" name = "txtName" value = "'& quot; FSDFDS"/> </Body> </Html> |