Example of using JavaScript code in HTML code, code javascript

Source: Internet
Author: User

Example of using JavaScript code in HTML code, code javascript

<Script> </script> label

To use JavaScript in HTML, you need to use the <script> </script> label and define the type attribute value as text/javascript, as shown in the preceding alert pop-up prompt box:

Copy codeThe Code is as follows:
<Script type = "text/javascript">
Alert ("I Am a text prompt! ");
</Script>

Generally, JavaScript code alone is meaningless. JavaScript code is generally used together with HTML code, because JavaScript was originally generated to make up for HTML defects. The following is an example of using JavaScript code and HTML code:

Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
Alert ("I Am a text prompt! ");
</Script>
</Head>
<Body>
<Div> image and text content </div>
</Body>
</Html>

Generally, JavaScript code (<script> </script> tag) is placed in the


Code for HTML + JAVASCRIPT

Please make a slight modification according to the example below

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
<Style>
<! --
# Foldheader {cursor: hand; font-weight: bold ;}
// -->
</Style>
<Script language = "JavaScript1.2">
<! --

Var head = "display :''"

Function change (){
If (! Document. all)
Return
If (event. srcElement. id = "foldheader "){
Var srcIndex = event. srcElement. sourceIndex
Var nested = document. all [srcIndex + 1]
If (nested. style. display = "none "){
Nested. style. display =''
}
Else {
Nested. style. display = "none"
}
}
}

Document. onclick = change

// -->
</Script>
</HEAD>

<BODY>
<Ul>
<Li id = "foldheader"> help 1 </li>
<Ul id = "foldinglist" style = "display: none">
<Li> help 1-content 1 </li>
<Li> help 1-content 2 </li>
<Li> help 1-content 3 </li>
</Ul>

<Li id = "foldheader"> help 2 </li>
<Ul id = "foldinglist" styl ...... remaining full text>

How to Use html code in javascript?

Do not use quotation marks. Try this way
Var tab = new TabBoard (document. getElementById ("radio_show"), document. getElementById ("radio_page"), document. getElementById ("radio_prev"), document. getElementById ("radio_next"), 140 );

[Loop]
Tab. add ('<a href = "{url}" {target}> </a> <a href = "{url}" title = "{title}" {target }>{ title} </a>' );
[/Loop]

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.