Method for outputting the & lt;/script & gt; tag in JavaScript, javascriptscript

Source: Internet
Author: User

Method for outputting the </script> label in JavaScript, javascriptscript

The '</script>' pop-up in JS will make JS mistakenly think that this is an end label, and an exception occurs.

As shown in the following code:

We use alert in the <script> block to pop up the '</script>' string. The result is mistakenly thought to be the end tag, and VIM has changed color. Running result

Because the string is treated as the end tag, an exception occurs. Obviously this is not the expected result. We only need to slightly process the code.

Use the plus sign to link the string in '</script>'. '</scr' + 'ipt'> 'to check the running result.

The program is normal. The string '</script>' is displayed correctly. In JS, if the string is connected by the plus sign, the plus sign is used to add the numbers.


How to call javaScript scripts in the <a> </a> label

<Html>
<Head>
<Script type = "text/javascript">
Function myf (){
Alert ("I am link 2 ");
}
</Script>
</Head>
<Body>
<A href = "javascript: alert ('I am the link 1')"> link 1 </a>
<A href = "#" onClick = "myf ()"> link 2 </a>
</Body>
</Html>

---------

Both of them are supported. The second type is recommended.

<Script type = "text/javascript"> How do I write code with line breaks?

I know what you mean. The code is divided into multiple sections and cannot be modified ......
This is quite troublesome, because the output is multi-line, and the string between quotation marks cannot be wrapped. So there is a problem and I am sorry that I didn't see it clearly at first.
I provide a solution, which is a little troublesome. For your reference, we will use the table you provided:
1. Put the automatically generated code (TAG) into a <script> tag pair, and eventually it looks like this:
<Script id = "s1" name = "ss">
/* <Table border = "1" width = "100%">
<Tr>
<Td width = "100%"> </td>
</Tr>
</Table> */
</Script>

2. Write in javascript Code as follows:
<Script>
Var s1Str = document. getElementById ("s1"). innerHTML;
Var pos1 = s1Str. indexOf ("/*");
Var pos2 = s1Str. indexOf ("*/");
S1Str = s1Str. substring (pos1 + 2, pos2 );
Document. write (s1Str );
</Script>

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.