分享人:周倩宇
挑兩個(gè)可能以后會遇到的介紹一下:
//document 方法:
getElementById(id) Node 返回指定結(jié)點(diǎn)的引用
getElementsByTagName(name) NodeList 返回文檔中所有匹配的元素的集合
createElement(name) Node Node
createTextNode(text) Node 創(chuàng)建一個(gè)純文本結(jié)點(diǎn)
ownerDocument Document 指向這個(gè)節(jié)點(diǎn)所屬的文檔
documentElement Node 返回html節(jié)點(diǎn)
document.body Node 返回body節(jié)點(diǎn)
//element 方法:
getAttribute(attributeName) String 返回指定屬性的值
setAttribute(attributeName,value) String 給屬性賦值
removeAttribute(attributeName) String 移除指定屬性和它的值
getElementsByTagName(name) NodeList 返回結(jié)點(diǎn)內(nèi)所有匹配的元素的集合
//node 方法:
appendChild(child) Node 給指定結(jié)點(diǎn)添加一個(gè)新的子結(jié)點(diǎn)
removeChild(child) Node 移除指定結(jié)點(diǎn)的子結(jié)點(diǎn)
replaceChild(newChild,oldChild) Node 替換指定結(jié)點(diǎn)的子結(jié)點(diǎn)
insertBefore(newChild,refChild) Node 在同一層級的結(jié)點(diǎn)前面插入新結(jié)點(diǎn)
hasChildNodes() Boolean 如果結(jié)點(diǎn)有子結(jié)點(diǎn)則返回 true
//node 屬性:
nodeName String 以字符串的格式存放結(jié)點(diǎn)的名稱
nodeType String 以整型數(shù)據(jù)格式存放結(jié)點(diǎn)的類型
nodeValue String 以可用的格式存放結(jié)點(diǎn)的值
parentNode Node 指向結(jié)點(diǎn)的父結(jié)點(diǎn)的引用
childNodes NodeList 指向子結(jié)點(diǎn)的引用的集合
firstChild Node 指向子結(jié)點(diǎn)結(jié)合中的第一個(gè)子結(jié)點(diǎn)的引用
lastChild Node 指向子結(jié)點(diǎn)結(jié)合中的最后一個(gè)子結(jié)點(diǎn)的引用
previousSibling Node 指向前一個(gè)兄弟節(jié)點(diǎn);如果這個(gè)節(jié)點(diǎn)就是兄弟節(jié)點(diǎn),那么該值為null
nextSibling Node 指向后一個(gè)兄弟節(jié)點(diǎn);如果這個(gè)節(jié)點(diǎn)就是兄弟節(jié)點(diǎn),那么該值為 null
// 日期型(Date) //1. 聲明
var myDate = new Date(); // 系統(tǒng)當(dāng)前時(shí)間
var myDate = new Date(yyyy, mm, dd, hh, mm, ss);
var myDate = new Date(yyyy, mm, dd);
var myDate = new Date("monthName dd, yyyy hh:mm:ss");
var myDate = new Date("monthName dd, yyyy");
var myDate = new Date(epochMilliseconds);
//2. 獲取時(shí)間的某部份
var myDate = new Date();
myDate.getYear(); //獲取當(dāng)前年份(2位)
myDate.getFullYear(); //獲取完整的年份(4位,1970-????)
myDate.getMonth(); //獲取當(dāng)前月份(0-11,0代表1月)
myDate.getDate(); //獲取當(dāng)前日(1-31)
myDate.getDay(); //獲取當(dāng)前星期X(0-6,0代表星期天)
myDate.getTime(); //獲取當(dāng)前時(shí)間(從1970.1.1開始的毫秒數(shù)) 時(shí)間戳!!
myDate.getHours(); //獲取當(dāng)前小時(shí)數(shù)(0-23)
myDate.getMinutes(); //獲取當(dāng)前分鐘數(shù)(0-59)
myDate.getSeconds(); //獲取當(dāng)前秒數(shù)(0-59)
myDate.getMilliseconds(); //獲取當(dāng)前毫秒數(shù)(0-999)
myDate.toLocaleDateString(); //獲取當(dāng)前日期
myDate.toLocaleTimeString(); //獲取當(dāng)前時(shí)間
myDate.toLocaleString( ); //獲取日期與時(shí)間
//3. 計(jì)算之前或未來的時(shí)間
var myDate = new Date();
myDate.setDate(myDate.getDate() + 10); //當(dāng)前時(shí)間加10天
// 類似的方法都基本相同,以set開頭,具體參考第2點(diǎn)
//4. 計(jì)算兩個(gè)日期的偏移量
var i = daysBetween(beginDate,endDate); //返回天數(shù)
var i = beginDate.getTimezoneOffset(endDate); //返回分鐘數(shù)
//5. 檢查有效日期
//checkDate()只允許"mm-dd-yyyy"或"mm/dd/yyyy"兩種格式的日期
if( checkDate("2006-01-01") ){ }
// 正則表達(dá)式(自己寫的檢查 yyyy-mm-dd, yy-mm-dd, yyyy/mm/dd, yy/mm/dd 四種)
var r = /^(\d{2}|\d{4})[/-]\d{1,2}[/-]\d{1,2}$/;
if( r.test( myString ) ){ }
數(shù)據(jù)資料來源:
http://www.cnblogs.com/hnyei/archive/2013/05/30/3107672.html
【友情提示:電腦打開地址瀏覽】