Examples of simple Javascript code application on Web pages

Source: Internet
Author: User

When you click an image (image or table element) on the left of the table and move it to the center of the table:

Reference content is as follows:
<Script language = "JavaScript">
Function call (xxx ){
Xxx. align = "left ";
}
Function letback (yyy ){
Yyy. align = "right ";
}
</Script>


The file is referenced as follows:

Reference content is as follows:
<Td id = "mainbtn3" align = "right" height = "31" onClick = "MM_showHideLayers ('layer1','', 'hide ', 'layer2 ','', 'hide ', 'lay3', '', 'show ') "width =" 250 "> </td>


Xp style menu Effect

Reference content is as follows:
<Script language = "JavaScript" type = "text/javascript">
<! --
Function rollon (){
A. style. backgroundColor = '# C8C8C8 ';
A. style. border = '#808080 solid 1px';} function roloff (){
A. style. backgroundColor = '# E4E4E4 ';
A. style. border = '# E4E4E4 solid 1px ';
}
// -->
</Script>
<Style type = "text/css">
<! --
. Off {background-color: # e4e4e4; border-color: # e4e4e4 # E4E4E4 # E4E4E4; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</Style>


HTML link:

Reference content is as follows:
<Tr>
<Td class = "off" onMouseOut = "roloff (this);" onMouseOver = "rollon (this);" height = "12"> <a href = "#">
Summary Report </a> </td>
</Tr>

 

Cool dynamic CLOCK with year, month, and day following the mouse

One link changes the content of multiple target frames.

Reference content is as follows:
<Script language = "javascript">
Function frame_loader (targetLeft, targetMain ){
Parent. leftFrame. location. href = targetLeft;
Parent. mainFrame. location. href = targetMain;
}
</Script>
<
Href = "javascript: frame_loader ('default _ left. asp ', 'default _ body. asp')"> Link </a>


Both the left and right clicks open the target page on this page.

Reference content is as follows:

<Script language = "JavaScript">
<! --
Function clicklink () {window. location = "index.html "}
// -->
</Script>

In html:

 

<Body bgcolor = "# FFFFFF" text = "#000000" onMouseDown = "clicklink ()">
 


Check screen resolution import different pages


Reference content is as follows:
<Script language = "JavaScript">
<! --
Function KBScreenGoToURL (Big, Medium, Small, Tiny ){
// Copyright (c) 1998 by Kevin Bartz. All rights reserved. This site has been enhanced by one of Kevin Bartz's behaviours! Mail him at kevinbartz@geocities.com! This line must remain in the script.
IE4 = (document. all )? 1:0
NS4 = (document. layers )? 1:0
If (NS4 | IE4 ){
Var h = screen. height
Var w = screen. width
If (h <580 & w <740 ){
Window. location = Tiny
} Else if (h <674 & w <835 ){
Window. location = Small

} Else if (h <768 & w <929 ){
Window. location = Medium
} Else {
Window. location = Big
}
}
}
// -->
</Script>

 


HTML:


Reference content is as follows:
<P>
<Body bgcolor = "# FFFFFF" onLoad = "kbscreengotourl('1024.htm', '1024.htm', '800.htm', '800.htm')">

 

Or use the following section:

Reference content is as follows:
<Html>
<Head>
<Script language = javascript>
<! --
Function mHref (){
If (screen. width = 1024) location. href = "htm2.htm ";
Else if (screen. width = 800) location. href = "htm1.htm ";
Else return (false );
}
// -->
</Script>
</Head>
<Body onload = "mHref ();">
</Body>
</Html>

 
Click a link to open two different page windows
<A href = "http://msdn.microsoft.com/vs/techinfo/" target = "_ blank" onClick = "too many open('temp.htm','', '')"> Visual Studio </A>

 

These two pages will be opened in a new window. If you want to open this page, you cannot use windo. open to use: window. location = "" or document. location. href = ""


Hide components such as drop-down boxes in the target area

Hide components such as the drop-down box of the target area so that it does not block the target layer (copied from Microsoft) when a layer (menu) appears)


The Code is as follows:

Reference content is as follows:

<Script language = "JavaScript" type = "text/javascript">
<! --
Function hideElement (elmID)
{
For (I = 0; I <document. all. tags (elmID). length; I ++)
{
Obj = document. all. tags (elmID) [I];
If (! Obj |! Obj. offsetParent)
Continue;
// Find the element's offsetTop and offsetLeft relative to the BODY tag.
ObjLeft = obj. offsetLeft;
ObjTop = obj. offsetTop;
ObjParent = obj. offsetParent;
While (objParent. tagName. toUpperCase ()! = "BODY ")
{
ObjLeft + = objParent. offsetLeft;
ObjTop + = objParent. offsetTop;
ObjParent = objParent. offsetParent;
}
If (objTop <250 ){
Obj. style. visibility = "hidden ";
}
}
}
Function showElement (elmID)
{
For (I = 0; I <document. all. tags (elmID). length; I ++)
{
Obj = document. all. tags (elmID) [I];
If (! Obj |! Obj. offsetParent)
Continue;
Obj. style. visibility = "";
}
}
Function hidelayer ()
{Var I; for (I = 1; I <= 4; ++ I) {document. all ['nav' + I]. style. visibility = 'den den ';}
ShowElement ("SELECT ");
ShowElement ("OBJECT ");
ShowElement ("IFRAME ");}
Function showlayer (index)
{Document. all ['nav' + index]. style. visibility = 'visable ';
HideElement ("SELECT ");
HideElement ("OBJECT ");
HideElement ("IFRAME ");}
// -->
</Script>
 

 

Related Article

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.