js 常用節點彙總

2021-08-31 04:38:17 字數 1236 閱讀 5789

nodename string 節點的定義,根據節點的型別而定義;

nodevalue string 節點的值,根據節點的型別而定義;

nodetype number 節點的型別常量值之一;

ownerdocument document 指向這個節點所屬的文件;

firstchild node 指向在childnodes中的第乙個節點;

lastchild node 指向在childnodes中的最後乙個節點;

childnodes nodelist 所有子節點的列表;

previoussibling node 指向前乙個兄弟節點;如果這個節點就是第乙個節點,那麼該值為null;

nextsibling node 指向下乙個兄弟節點;如果這個節點就是第乙個節點,那麼該值為null;

haschildnodes() boolean 當childnodes包含乙個或多個節點時,返回真;

attributes namednodemap 包含了代表乙個元素的特性的attr物件,僅用於element節點;

removechild 刪除node;

replacechild(newnode,oldnode) 替換node,即將oldnode替換成newnode;

insertbefore(newnode,refnode) 在childnodes中的refnode之前插入newnode;

處理屬性:

getnameditem(name):返回nodename屬性值等於name的節點;

removenameditem(name):刪除nodename屬性值等於name的節點;

setnameditem(node):將node新增到列表中,按其nodename屬性進行索引;

item(pos):跟nodelist一樣,返回在位置pos的節點;

example:

hello world

var sid=op.attributes.getnameitem("id").nodevalue;或 var sid=op.attributes.getnameitem(1).nodevalue;

var sid=op.getattribute("id");

op.setattribute("id","newid");

加節點:

var op=document.create_relement("p");

var otext=document.create_rtextnode("hello.");

js常用API彙總

typeof 檢測資料型別 string 轉換成字串 parseint 解析出乙個string或number的整數部分 parsefloat 解析出乙個string的浮點數部分 number 把乙個string解析為number blooean 轉換成布林型別 nan,undefined,null,...

js常用API彙總

typeof 檢測資料型別 string 轉換成字串 parseint 解析出乙個string或number的整數部分 parsefloat 解析出乙個string的浮點數部分 number 把乙個string解析為number blooean 轉換成布林型別 nan,undefined,null,...

js常用方法彙總

產生在m n之間的隨機整數 把數四捨五入為最接近的整數。function random m,n console.log random 20,30 20 30之間整數 將乙個dom元素劃分成多個小塊生成乙個陣列 位置,專案數量,新專案 返回值 array 新陣列 返回元素的高 function ele...