根据id选择元素 使用 getElementById() 获取对象。如果想从HTML页面里选择某个具有特定ID的元素,我们只要将该元素作为参数来调用 document 的 getElementById() 方法,它就会返回特定ID的页面元素所对应的DOM对象。 var myDiv = document.getElementById("div1");
Location对象 location对象包含当前加载页面的URL信息。例如对于一个URL: http://www.baidu.com:8080/tool/index.jsp?s=123#list
属性 | 内容 |
href | http://www.baidu.com:8080/tool/index.jsp?s=123#list |
protocal | http: |
host | www.baidu.com:8080 |
hostname | www.baidu.com |
port | 8080 |
pathname | /tool/index.jsp |
search | ?s=123 |
hash | #list |
日期和时间 Date对象用于处理日期和时间。在我们需要时需要主动创建自己的Date对象。 构造方法:var d1=new Date(95,9,22,10,57,0);//1995年10月22号10.57.0 var d2=new Date(95,9,10);//1995.10.22.0.0.0 var d3=new Date();//创建时间 对象方法:getFullYear()//1995 getMonth()//0开始 getDate()//1-31 getDay()//星期 0-6 getHours()//0-23 getMinutes()//0-59 getSeconds()//0-59
Math对象 Math对象不需要创建就可以使用,在此不再介绍。
关键字with 关键字with使用对象作为参数,代码块里的语句在调用该对象方法时可以不再指定该对象。
with(Math){
var myRand=random();
}