- window.onload VS document.onload VS body.onload
window.onload:the most widely supported
Within the brower when the page loads the order operations is roughly this:(页面加载过程)
1. HTML被解析。
2. 外部脚本/样式表被加载,如CSS,如JQUERY的外面库文件。
3. 文档解析过程中内联的脚本被执行,如在HTML页面内的脚本内容。
4. HTML DOM构造完成。================ document.onload
5. 图像和外部内容被加载。
6. 页面加载完成。====================== window.onloadwindow.onload vs body.onload ======== 前者 is good to separate the structure from the action.
some parts from:http://www.cnblogs.com/myjavawork/articles/1758819.html
- DOM0级和DOM2级事件
DOM0级:
var btn = document.getElementById("button"); btn.onclick = function(){ /*函数体*/ };
DOM2级:
var btn = document.getElementById("button"); btn.addEventListener("click", function(){ /*函数体*/ }, false);
- js中body元素的获取
document.body.innerHTML
var body = document.getElementsByTagName.body[0];
- document.write VS innerHTML
document.write:纯 js,会重绘整个页面
innerHTML:HTML DOM API相关,可以重绘页面的一部分
后者更常用,object.innerHTML = "这里是需要显示的内容";
- js数组操作方法:splice和slice
前者可删除splice(0,1),插入splice(2,0,"red","blue"),替换splice(2,1,"black","white")。(起始项,删除的项数),返回一个数组,包含删除的项。
后者不影响原始数组,创建新数组slice(1,4)或slice(1)。(起始项,终止项),返回一个数组,包含指定项。
-
js函数
无重载。(在js中均被视作覆盖)function compare(a, b) { }