HTML DOM->一般的に使用されるノードの属性

1.ノードに共通のプロパティ

  nodeName、nodeType、nodeValue

  例:

<!DOCTYPE html > 
< html > 
    < head > 
        < meta charset = "utf-8" > 
        < title > js_excise </ title > 
        < script src = "./ js / js_excise.js" type = "text / javascript" charset = " utf-8 " > </ script > 
    </ head > 
    < body style =" height:187.5rem; " > 
        < button id = "in" style = "background-color:red;" >更新</ ボタン> 
        < 入力タイプ= "テキスト" = "テキスト" プレースホルダー= " 名前を入力して   ください" my = 'abner' > 
        < スクリプトタイプ= "text / javascript" > 
            var jsDiv = document.getElementById(' in ' 
            console.log(' 属性节点:' 、jsDiv)
            console.log(' ノード名' 、jsDiv.nodeName)
            console.log(' ノードタイプ:、jsDiv.nodeType)
            console.log(' nodeValue:' 、jsDiv.nodeValue)
         </ script > 
    </ body > 
</ html >

  出力:

 

 2.ノードの階層関係属性

  1>現在の要素ノードのすべての子ノードを取得します

var childNodesArray = jsDiv.childNodes; 
console.log(childNodesArray);

  2>現在の要素ノードの最初の子ノードを取得します

var firstchildNode = jsDiv.firstchild; 
console.log( firstchildNode );

  3>現在の要素ノードの最後の子ノードを取得します

var last childNode = jsDiv.lastchild; 
console.log(lastchildNode);

  4>このノードのドキュメントのルートノードを取得します。ドキュメントと同等です

var rootNode = jsDiv.ownerDocument; 
console.log(rootNode);

  5>現在のノードの親ノードを取得します

var parentNode = jsDiv.parentNode; 
console.log(parentNode);

  6>現在のノードの前の兄弟ノードを取得

var previousNode = jsDiv.previousSibling; 
console.log(previousNode);

  7>現在のノードの次の兄弟ノードを取得します

var nextNode = jsDiv.nextSibling; 
console.log(nextNode);

  8>現在のノードのすべての属性ノードを取得します

var jsInput = document.getElementById( "put"); 
var allAttributesArry = jsInput.attributes;
console.log(allAttributesArray);

おすすめ

転載: www.cnblogs.com/abner-pan/p/12748227.html