XML DOM hasAttributeNS() methode
Definitie en gebruik
Als de eigenschap bestaat uit de opgegeven naamruimte en naam, retourneert de methode hasAttributeNS() true, anders retourneert het false.
语法:
hasAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to be retrieved. |
name | Required. Specifies the name of the attribute to be retrieved. |
Description
This method is similar to hasAttribute() methodSimilar, but the attribute to be checked is specified by namespace and name. Only XML documents that use namespaces use the method.
instance
In all examples, we will use the XML file books_ns.xml, and the JavaScript function loadXMLDoc().
The following code snippet checks if the first <title> element in "books_ns.xml" has an attribute with the specified namespace and name:
xmlDoc=loadXMLDoc("books_ns.xml");
x=xmlDoc.getElementsByTagName("title")[0];
ns="http://www.codew3c.com/children/";
document.write(x.hasAttributeNS(ns,"lang")
);
The output of the above code:
true