// 10
JS 中,一些東西停用三種展現方式。
我們在WEB項目中,有時候需要在使用者點擊某個東西的時候,一些東西不可用。如果在用戶端實現。最簡單的就是利用disabled 。下面羅列的其中三種方式:依次是:不可用(disabled);用一個空白來代替這個地方(Blank);這個地區為空白(None)。具體可以查看這個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> <INPUT type=checkbox> </DIV>
<P><INPUT onclick=ShowDisableObject(Show01); type=button value=Disable> <INPUT id=Button1 onclick=ShowBlankObject(Show01); type=button value=Blank name=Button1> <INPUT id=Button2 onclick=ShowNoneObject(Show01); type=button value=None name=Button2> </P><!--示範代碼結束//-->
On this page I explain a simple DHTML example script that features invisibility,
moving and the changing of text colour.
Example
Test TextMake test text invisible.
Make test text visible.
Move test text 50 pixels down.
Move test text 50 pixels up.
Change colour to red.
Change colour to blue.
Change colour 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) ? ’hidden’ : ’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;
}