Common JavaScript code (6)

Source: Internet
Author: User

 

// 10

In JS, some things are unavailable in three ways.
In web projects, some items are unavailable when users click something. If it is implemented on the client. The simplest is to use disabled. The following three methods are listed: Disabled; blank; and none ). For details, see the source file of this blog:
OBJ. Disabled = false;
OBJ. style. Visibility = "hidden ";
OBJ. style. Display = "NONE ";

<Script language = JavaScript>
Function showdisableobject (OBJ)
{
If (obj. Disabled = false)
{
OBJ. Disabled = true;
}
Else {
OBJ. Disabled = false;
}
VaR coll = obj. All. Tags ("input ");
If (Coll! = NULL)
{
For (VAR I = 0; I <Coll. length; I ++)
{
Coll [I]. Disabled = obj. Disabled;
}
}
}
Function showblankobject (OBJ)
{
If (obj. style. Visibility = "hidden ")
{
OBJ. style. Visibility = "visible ";
}
Else
{
OBJ. style. Visibility = "hidden ";
}
}
Function shownoneobject (OBJ)
{
If (obj. style. Display = "NONE ")
{
OBJ. style. Display = "Block ";
}
Else
{
OBJ. style. Display = "NONE ";
}
}
</SCRIPT>
<P> </P>
<Div id = show01> dadd
<Div> CCC </div> <input type = checkbox> </div>
<P> <input onclick = showdisableobject (show01); type = button value = Disable> <input id = button1 onclick = showiankobject (show01 ); type = button value = blank name = button1> <input id = button2 onclick = shownoneobject (show01); type = button value = none name = button2> </P> <! -- End the Demo code // -->

On this page I explain a simple DHTML example script that features invisibility,
Moving and the changing of text color.

Example
Test textmake test text invisible.
Make Test text visible.
Move test text 50 pixels down.
Move test text 50 pixels up.
Change color to red.
Change color to blue.
Change color to black.
Change the font style to italic.
Change the font style to normal.
Change the font family to 'times '.
Change the font family to 'arial '.

The script
The scripts work on this HTML element:
<Div id = "text"> test text </div>
# Text {position: absolute;
Top: 400px;
Left: 400px;
Font: 18px Arial;
Font-weight: 700;
}
These scripts are necessary for the three effects:
VaR DHTML = (document. getelementbyid | document. All | document. layers );
Function getobj (name)
{
If (document. getelementbyid)
{
This. OBJ = Document. getelementbyid (name );
This. Style = Document. getelementbyid (name). style;
}
Else if (document. All)
{
This. OBJ = Document. All [name];
This. Style = Document. All [name]. style;
}
Else if (document. layers)
{
This. OBJ = Document. Layers [name];
This. Style = Document. Layers [name];
}
}
Function invi (FLAG)
{
If (! DHTML) return;
VaR x = new getobj ('text ');
X. style. Visibility = (FLAG )? 'Siden': 'visible'
}
VaR texttop = 400;
Function move (amount)
{
If (! DHTML) return;
VaR x = new getobj ('text ');
Texttop + = amount;
X. style. Top = texttop;
}

Function changecol (COL)
{
If (! DHTML) return;
VaR x = new getobj ('text ');
X. style. Color = Col;
}

 

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.