Javascript dom programming (2): common objects 1, javascriptdom
I. history Object
<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> untitled document </title>
</Head>
<Script type = "text/javascript">
// The history Object records the url accessed by the user
Function myback (){
Window. alert (history. length );
Window. history. go (-1 );
}
</Script>
<Body>
<H1> B .html <Input type = "button" onClick = "myback ()" value = "return to previous page 1"/>
</Body>
</Html>
Ii. location object
<Script type = "text/javascript">
// The location object contains the information of the current url
Function myfresh (){
Window. location. reload ();
}
// Refresh the page every 10 seconds
Window. setInterval ("myfresh ()", 10000 );
</Script>
Iii. navigator object
<Script type = "text/javascript">
// Navigator the object contains information about the browser. You can retrieve all attributes of the object through traversal.
For (var key in navigator ){
Document. write ("<br>" + key + "=" + navigator [key]);
}
</Script>
Iv. event object
Case 1:
<Script type = "text/javascript">
Var I = 5;
Function countTime (){
I --;
Mybut. value = "agree" + I;
If (I = 0 ){
Mybut. disabled = false;
Window. clearInterval (mytimer );
}
}
Var mytimer = window. setInterval ("countTime
() ", 1000 );
</Script>
<Body>
<P>
Terms of Registration
</P>
<Input type = "button" id = "mybut" disabled = "true" value = "agree 5">
</Body>
Case 2: Detect mouse movement
<Script type = "text/javascript">
Function test (){
Showxy. innerText = "x =" + window. event. screenX + "y =" + window. event. screenY;
}
</Script>
</Head>
<Body>
<Div onmousemove = "test ();" style = "width: 400px; height: 300px; border: 1px solid red;">
</Div>
<Span id = "showxy"> </span>
</Body>
Case 3:
<Script type = "text/javascript">
// In the text box, enter a six-digit number. The first digit cannot be 0 or exceed the six-digit number. It must be a number,
Var I = 0;
Function checkNum (obj ){
If (I = 6 ){
Window. alert ("input string length> 6 ");
Return false;
}
// The first digit cannot be 0
If (I = 0 ){
If (window. event. keyCode = '0'. charCodeAt (0 )){
Alert ('priority cannot be 0 ');
Return false;
}
}
If (window. event. keyCode <'0'. charCodeAt (0) | window. event. keyCode> '9'. charCodeAt (0 )){
Alert ("You did not enter a number ");
Return false;
} Else {
I ++;
}
}
</Script>
</Head>
<Body>
Enter a six-digit <input type = "text" id = "pageNow" onkeydown = "return checkNum (this)"/>
</Body>
Copyright statement: original post of the blogger. For details, refer to the source. Http://blog.csdn.net/dzy21