طريقة XML DOM hasAttributeNS()
تعريف والاستخدام
إذا كان الخصائص مكونة من مسمى الفضاء والمسمى المحدد، فإن طريقة hasAttributeNS() تعود إلى true، وإلا فإنها تعود إلى 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 JavaScript function loadXMLDoc().
The following code snippet checks whether 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")
);
Output code above:
true