一:window对象
- alert() //警告框
- prompt() //对话框
- confirm() //确认框
- open() //打开一个窗口
- close() //关闭窗口
- print() //打印窗口内容
- focus() //聚焦
二:JavaScript计时器
- setTimeout("clock()",1000) //指定的延迟时间之后来执行代码
- clearTimeout(计时器) //取消setTimeout的设置
- setInterval("clock()",1000) //每隔指定的时间执行代码
- clearInterval() //取消setInterval的设置
三: History对象
- window.history.back(); //加载history的前一个URL
- window.history.forward(); //加载history的下一个URL
- window.history.go(number); //加载history列表中的具体某个页面(-1//前一个,0,1//下一个)
- window.history.length; //返回浏览器历史列表的URL数量
四: DOM对象
- getElementById()方法
- getElementsByName()方法 //length是指相同name的个数
- getElementsByTagName()方法//获取节点,例li
- getAttribute()方法 //Obj.getAttribute(name)通过元素节点名获取值
- setAttribute(name,value)方法
- firstChild/lastChild //Obj.firstChild
- nextSibling/previousSibling //访问兄弟节点,若无节点返回空
- appendChild(node) //插入节点
-
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <ul id="test"> <li>JavaScript</li> <li>HTML</li> </ul> <script type="text/javascript"> var otest = document.getElementById("test"); var newnode=document.createElement("li"); newnode.innerHTML="PHP"; otest.appendChild(newnode); </script> </body> </html>
- insertBefore() //插入在节点之前 例:
//在script 标签内补充代码,实现创建一个新li标签,内容为"php",并将新创建的li插入到内容为HTML的标签 前 <ul id="test"><li>JavaScript</li><li>HTML</li></ul> <script type="text/javascript"> var otest = document.getElementById("test"); var newnode=document.createElement("li"); newnode.innerHTML="PHP"; otest.insertBefore(newnode,otest.childNodes[1]); </script>
- removeChild() //删除节点
- replaceChild() //替换节点
- createElement("类型(li)") //创建元素节点