HTML DOM Element getAttributeNode() 方法

定义和用法

getAttribute() 方法返回指定属性名的属性值,以 Attr 对象。

替代方案:

使用 getAttribute() 方法 会更容易。

另请参阅:

setAttribute() 方法

hasAttribute() 方法

removeAttribute() 方法

setAttributeNode() 方法

removeAttributeNode() 方法

教程:

HTML အခြေခံ

参考手册:

HTML DOM Attribute 对象

知识点:getAttribute() 和 getAttributeNode() 的区别

getAttribute() 方法返回属性的值。

getAttributeNode() ဘဏ္ဍာရ ပြန်လည်ပေး Attr ဆိုင်းအကျိုးဆက် အကျိုးဆက် Attr value အခြေအနေ အကျိုးဆက် အကျိုးဆက်

အကျိုးဆက် အကျိုးဆက် အကျိုးဆက်

အကျိုးဆက်

အကျိုးဆက် 1

<h1> အခြေအနေ၏ class အခြေအနေ ဆိုင်း အကျိုးဆက်မှု ကို ရယူရန်

const element = document.getElementsByTagName("H1")[0];
let text = element.getAttributeNode("class").value;

ကိုယ်တိုင် စစ်ဆေးကြည့်ရန်

အကျိုးဆက် 2

<a> အခြေအနေ၏ target အခြေအနေ ဆိုင်း အကျိုးဆက်မှု ကို ရယူရန်

var elmnt = document.getElementById("myAnchor");
var attr = elmnt.getAttributeNode("target").value;

ကိုယ်တိုင် စစ်ဆေးကြည့်ရန်

အကျိုးဆက် 3

<button> အခြေအနေ၏ onclick အခြေအနေ ဆိုင်း အကျိုးဆက်မှု ကို ရယူရန်

var elmnt = document.getElementById("myBtn");
var attr = elmnt.getAttributeNode("onclick").value;

ကိုယ်တိုင် စစ်ဆေးကြည့်ရန်

အဓိပ္ပာယ်

element.getAttributeNode(name)

ပါဝင်

ပါဝင် ဖော်ပြ
name လိုအပ်

ပြန်လည်ပေး

အမျိုးအစား ဖော်ပြ
အကျိုးဆက်မှု အခြေအနေ ဆိုင်း အကျိုးဆက်မှု
null အခြေအနေ မရှိဘဲ

ဖော်ပြ

getAttributeNode() ဘဏ္ဍာရ သည် သတ်မှတ်ထားသော အခြေအနေ၏ အကျိုးဆက်မှု ကို ကိုယ်စားပြုသော Attr ဆိုင်း ကို ပြန်လည်ပေးသည်။ ကျွန်ုပ်သည် Node ဆိုင်း မှ တိုက်ဆိုင်သော attributes အခြေအနေ၏ ကို မှတ်ချက်များ ကို မွန်းကျင်း ပြန်လည်ပေးနိုင်ပါ။

ဘရာဇီး ထောက်ပံ့

element.getAttributeNode() ဒါဟာ DOM Level 1 (1998) အခြေခံအရာ ဖြစ်ပါသည်。

အားလုံး ဘရာဇီး သို့ အပြည့်အဝင် ထောက်ပံ့ပေးသည့််

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
ထောက်ပံ့ 9-11 ထောက်ပံ့ ထောက်ပံ့ ထောက်ပံ့ ထောက်ပံ့