The examples in this article tell you how to implement multiple JavaScript effects in the same Web page. Share to everyone for your reference. The specific analysis is as follows:
In general, if there are two <script type= "Text/javascript" ></script> tags in the Web page, all Javascipt scripts will not take effect again, only one time <script Type= "Text/javascript" ></script> tags, however, multiple JavaScript effects are often required on the same Web page.
I. BASIC OBJECTIVES
Mount two JavaScript clocks in a Web page, one of which is the normal time to walk every 1 seconds, and the other is an abnormal clock that goes every 3 seconds, just to differentiate to illustrate how to implement multiple JavaScript effects in the same Web page. The effect is shown in the following illustration:
Second, the production process
Method One:
Copy Code code as follows:
<script type= "Text/javascript" >
function Clocka () {
var time = new Date (). toLocaleString ();
document.getElementById ("Clocka"). InnerHTML = time;
}
function A () {
Clocka ();
SetInterval ("Clocka ()", 1000);
}
function clockb () {
var time = new Date (). toLocaleString ();
document.getElementById ("clockb"). InnerHTML = time;
}
Function B () {
CLOCKB ();
SetInterval ("clockb ()", 3000);
}
</script>
<body onload= "A (), B ()" >
<div id= "Clocka" ></div>
<div id= "CLOCKB" ></div>
</body>
First of all to achieve the effect of writing to a function, function A (), B (), and then through the body of the onload, let it load the Web page immediately to load this function.
As for Clocka () and clockb (), they are rewritten based on the original JavaScript code. The JavaScript code that originally was in <body> is as follows:
Copy Code code as follows:
<script type= "Text/javascript" >
function Clock () {
var time = new Date (). toLocaleString ();
document.getElementById ("Clock"). InnerHTML = time;
}
SetInterval ("clock ()", 1000);
</script>
Method Two:
is to write type directly in <script> without writing type types, but this method has a certain delay, the effect is a load, if too many special effects, the result will be bad.
But the neat and intuitive nature of the code is a triumph over the above method.
The code is as follows:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script>
function Clocka () {
var time = new Date (). toLocaleString ();
document.getElementById ("Clocka"). InnerHTML = time;
}
function clockb () {
var time = new Date (). toLocaleString ();
document.getElementById ("clockb"). InnerHTML = time;
}
</script>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>twojs</title>
<body>
<script>
SetInterval ("Clocka ()", 1000);
</script>
<script>
SetInterval ("clockb ()", 3000);
</script>
<div id= "Clocka" ></div>
<div id= "CLOCKB" ></div>
</body>
The
wants this article to help you with your JavaScript programming.