JavaScript DOM Programming (2): Common objects 1

Source: Internet
Author: User

A: The History object
<!doctype html>
<meta charset= "Utf-8" >
<title> Untitled Document </title>
<script type= "Text/javascript" >
History object records URL of user access
function Myback () {
Window.alert (history.length);
Window.history.go (-1);
}
</script>
<body>
<input type= "button" onclick= "Myback ()" value= "Back to last page 1"/>
</body>


II: Location Object
<script type= "Text/javascript" >
The Location object contains information about the current URL
function Myfresh () {
Window.location.reload ();
}
Refresh the page every 10 seconds
Window.setinterval ("Myfresh ()", 10000);

</script>


Three: Navigator Object
<script type= "Text/javascript" >
Navigator This object includes information about the browser and wants to see all the properties under that object can be obtained through traversal.
for (var key in navigator) {
document.write ("<br>" +key+ "=" +navigator[key]);
}

</script>


Four: Event object
Case One:
<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>
Registration terms
</p>
<input type= "button" id= "Mybut" disabled= "true" value= "Agree 5" >
</body>
case TWO: detecting mouse movement
<script type= "Text/javascript" >
function Test () {
showxy.innertext= "x=" +window.event.screenx+ "y=" +window.event.screeny;
}
</script>
<body>

<div onmousemove= "Test ();" style= "width:400px;height:300px;border:1px solid red;" >

</div>

<span id= "Showxy" ></span>
</body>
Case Three:
<script type= "Text/javascript" >
Enter a six-digit number in the text box, the first digit cannot be 0, cannot exceed the six-digit number, must be all numbers,
var i=0;
function Checknum (obj) {
if (i==6) {
Window.alert ("Input string length >6");
return false;
}
The first one can't be 0.
if (i==0) {
if (window.event.keycode== ' 0 '. charCodeAt (0)) {
Alert (' The first cannot be 0 ');
return false;
}
}
if (window.event.keycode< ' 0 '. charCodeAt (0) | | Window.event.keycode> ' 9 '. charCodeAt (0)) {
Alert ("You don't enter a number");
return false;
}else{
i++;
}
}
</script>
<body>
Please enter a six-digit number <input type= "text" id= "Pagenow" onkeydown= "return Checknum (This)"/>
</body>

Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21

JavaScript DOM Programming (2): Common objects 1

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.