javascript 常用代码大全(六)
2008-10-14 16:41
417 查看
// 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;
}
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;
}
相关文章推荐
- javascript 常用代码大全(超级收藏,强烈推荐)
- javascript 常用代码大全
- Javascript常用代码大全
- javascript 常用代码大全
- javascript 常用代码大全
- javascript 常用代码大全(超级收藏,强烈推荐)
- javascript 常用代码大全(超级收藏,强烈推荐)(2)
- javascript 常用代码大全
- javascript 常用代码大全
- javascript 常用代码大全(七)
- javascript 常用代码大全
- javascript 常用代码大全
- javascript 常用代码大全(2)
- javascript 常用代码大全(超级收藏,强烈推荐)(3)
- javascript 常用代码大全
- javascript 常用代码大全(八)
- javascript 常用代码大全(强烈推荐)(1)
- javascript 常用代码大全 zt
- javascript 常用代码大全
- javascript 常用代码大全(强烈推荐)(1)