// 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;
}