創建新節點:document.createElement(elementName)
添加新節點:parentNode.appendChild(newNode)
parentNode.insertBefore(newNode,refNode)
刪除節點: node.removeChild(childNode)必須由父節點刪除其下屬的某個子節點。
自定義對象:
1、直接創建對象
var personObj = new Object();
personObj.name = "kk";
personObj.say = new Function() {
alert("hello,world")
}
personObj.say();
2、用構造器創建對象。
function Person(name,age) {
this.name = name;
this.age = age;
this.showName = function() {
alert("hello")
};
this.test = test();
}
function test() {
alert(this.name+" "+this.age);
}
3、用JSON創建對象。
var student = {
"name":"kk",
"age ":44
};
alert(student.name);
事件:
1、鼠標事件(onclick,ondblclick,onmousedown,onmouserup,onmouserover,onmouseout)
2、鍵盤事件 (onkeydown,onkeyup)
3、狀態改變事件 (onload,onchange,onfocus,onblur,onsubmit)
取消事件:onXXX="return false"
事件對象:event
屬性:clientX、clientY、
在IE中可以直接使用event對象,而火狐中則不可以直接使用。可以作爲參數傳入
例如:func(even) function func(e){alert(e.clientX)}
使用event對象獲取事件源對象。IE、event.srcElement 火狐、event.target
爲了兼容:var obj = e.srcElement || e.target
事件處理機制是:冒泡機制,解決方法時:event.stoptPropagation();event.cancelBubble=true;