XML DOM နှိုင်းယှဉ်DocumentPosition() နည်းလမ်း
❮ Node Object
ဥပမာ
အောက်ပါကုဒ်အပိုင်းအစသည် " books.xml " ကို xmlDoc တွင်တင်ပြီး DOM အထက်တန်းအဆင့်ရှိ node နှစ်ခု (ပထမနှင့် တတိယ <book> ဒြပ်စင်) ၏နေရာချထားမှုကို နှိုင်းယှဉ်သည်-
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName('book')[0];
var y =
xmlDoc.getElementsByTagName('book')[2];
document.getElementById("demo").innerHTML =
x.compareDocumentPosition(y);
}
အထက်ဖော်ပြပါ ကုဒ်၏ အထွက်သည်-
4
ဘရောက်ဆာအများစုသည် အလွတ်အဖြူကွက်များ သို့မဟုတ် စာကြောင်းအသစ်များကို စာသား node များအဖြစ် သဘောထားကာ IE 9 နှင့် အစောပိုင်းတွင် လုပ်ဆောင်မည်မဟုတ်ပါ။ အထက်ဖော်ပြပါ ဥပမာတွင်၊ ဘရောက်ဆာအများစုသည် 4 ထွက်မည်ဖြစ်ပြီး IE 9 နှင့် အစောပိုင်းတွင် 2 ထွက်မည်ဖြစ်သည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နှိုင်းယှဉ်DocumentPosition() နည်းလမ်းသည် DOM အထက်တန်းအဆင့် (စာရွက်စာတမ်း) ရှိ node နှစ်ခု၏ နေရာချထားမှုကို နှိုင်းယှဉ်သည်။
Browser ပံ့ပိုးမှု
နှိုင်းယှဉ်DocumentPosition() နည်းလမ်းကို အဓိက ဘရောက်ဆာအားလုံးတွင် ပံ့ပိုးထားသည်။
မှတ်ချက်- Internet Explorer 9 နှင့် အထက်တွင် ဤနည်းလမ်းကို မပံ့ပိုးပါ။
အထားအသို
nodeObject.compareDocumentPosition(node)
ကန့်သတ်ချက်များ
Parameter | Type | Description |
---|---|---|
node | Node object | Required. Specifies the node to compare with the current node |
တန်ဖိုးကို ပြန်ပေးသည်။
Type | Description |
---|---|
Number | A Number representing where the two nodes are positioned compared to each other. The possible return values
are:
1 - No relationship, the two nodes do not belong to the same document. 2 - The specified node precedes the current node. 4 - The specified node follows the current node. 8 - The specified node contains the current node. 16 - The specified node is contained by the current node. 32 - The specified and the current node have no common container node or the two nodes are different attributes of the same node. Note: The return value could also be a combination of values. E.g. a return value of 20 means that the specified node is contained by the current node (16) AND the specified node follows the current node (4). |
နည်းပညာဆိုင်ရာအသေးစိတ်
DOM ဗားရှင်း | Core Level 3 Node Object |
---|
❮ Node Object