Javascript dom programming (2): common objects 1, javascriptdom

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.