1.1 Finding elements
document.getElementById ("id"); Find the most one by ID;
var A=document.getelementbyid ("id"); Place the found element in a variable;
Document.getelementbynames ("name"); Search by name, find the array;
Document.getelementbytagnames ("name"); According to the table signature, find out the array;
Document.getelementbyclassnames ("name"); According to table classname, find out the array;
alert (a.innerhtml); The HTML code and text in the tag are captured.
alert (a.innertext); get only the text inside;
Alert (a.outhtml), including the contents of the label itself;
1.2 Operating elements
var A=var a=document.getelementbyid ("id");
A.setattribute ("attribute name", "attribute value"); Set a property, add or change all can;
A.getattribute ("attribute name"); Get property value;
A.removeattribute ("attribute name"); Remove a property
Example: Show automatic and manual transitions for pictures, and insert hyperlinks.
Code:
<style>
#zlunbo
{Background-image:url (zk2.png); width:830px; height:540px; position:relative; margin-left:250px;}
#zzuo
{
width:33px;
height:124px;
Position:absolute;
Left: -30px;
top:214px;
line-height:124px;
font-size:50px;
}
#zzuo: hover
{background-color: #C7C7C7; opacity:60%;
}
#zyou
{
width:33px;
height:124px;
Position:absolute;
left:831px;
top:214px;
line-height:124px;
font-size:50px;
}
#zyou: hover
{background-color: #C7C7C7; opacity:60%;
}
</style>
<body>
<div id= "Zlunbo" ><a target= "new" id= "Zll" ><div style= "height:540px;" ></div></a>
<div id= "Zzuo" onclick= "Dodo ( -1)" > < </div>
<div id= "zyou" onclick= "Dodo (1)" > > </div>
</div>
</body>
<script>
Var jpg=new Array ();
jpg[0]= "url (zk2.png)";
jpg[1]= "url (zt1.png)";
jpg[2]= "url (zx1.png)";
Var xb =0;var n=0;var Lbimg=document.getelementbyid ("Zlunbo")
Function Huan ()
{xb++;
if (xb==3)
{xb=0}
Lbimg.style.backgroundimage=jpg[xb];
if (n==0)
{window.settimeout ("Huan ()", 4000);}
var Zll1=document.getelementbyid ("Zll"). href
var zllianjie=new Array ();
zllianjie[0]= "http://www.baidu.com"
zllianjie[1]= "http://www.360.com"
zllianjie[2]= "http://www.qq.com"
document.getElementById ("Zll"). Href=zllianjie[xb]
}
Function Dodo (m)
{n=1;
Xb=xb+m;
if (xb<0)
{xb=2;}
Else if (xb>=3)
{xb=0;}
LBIMG.STYLE.BACKGROUNDIMAGE=JPG[XB];
var Zll1=document.getelementbyid ("Zll"). href
var zllianjie=new Array ();
zllianjie[0]= "http://www.baidu.com"
zllianjie[1]= "http://www.360.com"
zllianjie[2]= "http://www.qq.com"
document.getElementById ("Zll"). Href=zllianjie[xb]
}
Window.settimeout ("Huan ()", 4000);
</script>
Windows.document Object