JavaScript string not ending resolution

Source: Internet
Author: User

Web page effect string not finished resolution

My solution has two, one is to replace the string variable operation, the double quotes into single quotes

, the single quotation mark is replaced with "", but it is replaced with the original text when it is passed; the second method is

Instead of directly passing the data in the form of arguments, you assign it to a hidden text, and the function simply reads

Take the contents of the text

One is the JS file and page encoding inconsistent, resulting in special characters within the file due to inconsistent format will be in the decoding

is garbled, causing the compiler to end prematurely before the quote ("or") is reached, resulting in an "unfinished

string constant ".

Solution: If the external introduction of JS files, can be in <script type Text/javascript "

Src= "Xxx.js" charset= "###′>
Set charset= "###" in accordance with your Web page encoding is OK;

Second in JavaScript, strings are not matched or nested incorrectly before and after a string (such as single or double quotes)

Miss

Workaround: Put the front and back quotes correctly paired; When a total of two layers are nested, the double quotes embedded nested single quotes are

Correct, single quotes inline with double quotes are also correct. When there are three layers of nesting, the innermost quotation marks cannot

This is the same as the outermost layer, which is wrong, and can be preceded by an escape character "" in the innermost quotation mark.

Three JavaScript strings cannot span lines, the source code is as follows:

document.write (' <table width=770 border=0 cellpadding=0 cellspacing=0>
<tr>
<td></td>
<td></td>
</tr>
</table> ')
Line:2
char:71
code:0
Error: not ending string constant
Workaround:

One method uses N to separate each line of source code to:

document.write (' <table width=770 border=0 cellpadding=0n

Cellspacing=0>n<tr>n<td>

/></td>n<td>

/></td>n</tr>n</table> ');

Another method uses multiple document.write output statements, such as the following code changes:

1.document.writeln (' <table width=770 border=0 cellpadding=0

');d Ocument.writeln (' cellspacing=0> '); 2.document.writeln (' <tr> ');

3.document.writeln (' <td></td> ');

4.document.writeln (' <td></td>

</tr> '); 5.document.writeln (' </table> '); Four-pass parameter variables or script variables

Contains the HTML markup language, contains line breaks, or contains quotes:

This situation is the most difficult to find, easy to ignore the variables inside the text caused by the character

When a string is passed as a parameter to a function or to an HREF or an action, the string contains line breaks, quotation marks

or HTML tags, causing this error. such as: A. It is normal to use a single line of data in the test without this error

This error occurs when you use multiple lines of data and use the return key to wrap lines, because they contain line breaks. Source

Code b.marray[<%=n_id%>]= "<%=loopnum%><><%=n_topic%><><%=state%><><%

=n_sendtime%><><%=n_content%> "; seemingly correct, but <%=n_topic%>, <%=n_content%>

This error occurs when more than one double quotation mark is included in the

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.