XML DOM hasAttributes() Method
Definition and Usage
Kung ang tinukoy na node ay may anumang attribute: hasAttributes()
The method returns true, otherwise false.
Note:Kung ang tinukoy na node ay hindi Element node, ang halimbawa ay palaging false.
Syntax
nodeObject.hasAttributes()
Parameters
None.
Technical Details
DOM Version: | Core Level 2 Node Object |
---|---|
Halimbawa ng Balyage: | Boolean value. Kung ang tinukoy na node ay may anumang attribute, ibabalik ang true, kung hindi, ibabalik ang false. |
Mga halimbawa
Ang mga sumusunod na kodigo ay maglalaad ng "books.xml" sa xmlDoc at ibabalik kung ang unang <book> elemento ay may anumang attribute:
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]; document.getElementById("demo").innerHTML = x.hasAttributes(); {}
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |
所有主流浏览器都支持 hasAttributes()
方法。
注释:Internet Explorer 9 及更早版本不支持此方法。