XML DOM removeAttributeNode() ·½·¨
¶¨ÒåºÍÓ÷¨
removeAttributeNode() ·½·¨´ÓÔªËØÖÐɾ³ýÖ¸¶¨µÄÊôÐԽڵ㡣
Óï·¨£º
elementNode.removeAttributeNode(node)
²ÎÊý | ÃèÊö |
---|---|
node | ±ØÐ衣Ҫɾ³ýµÄ½Úµã¡£ |
·µ»ØÖµ
ɾ³ýµÄ Attr ½Úµã¡£
˵Ã÷
¸Ã·½·¨´Óµ±Ç°ÔªËصÄÊôÐÔ¼¯ºÏÖÐɾ³ý£¨²¢·µ»Ø£©Ò»¸ö Attr ½Úµã¡£Èç¹û DTD ¸øÉ¾³ýµÄÊôÐÔÉèÖÃÁËĬÈÏÖµ£¬ÄÇô¸Ã·½·¨½«Ìí¼ÓÒ»¸öÐ嵀 Attr ½Úµã£¬±íʾÕâ¸öĬÈÏÖµ¡£Óà removeAttribute() ·½·¨´úÌæ¸Ã·½·¨ÍùÍù»á¸ü¼òµ¥¡£
ʵÀý
ÔÚËùÓеÄÀý×ÓÖУ¬ÎÒÃǽ«Ê¹Óà XML Îļþ books.xml£¬ÒÔ¼° JavaScript º¯Êý loadXMLDoc()¡£
ÏÂÃæ´úÂëÆ¬¶Î´Ó "books.xml" ÖеÄËùÓÐ <book> ÔªËØÖÐɾ³ý "category" ÊôÐÔ£º
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
old_att=x.item(i).removeAttributeNode(attnode)
;
document.write("Removed attribute: " + old_att.name + "<br />");
}
Êä³ö£º
Removed attribute: category Removed attribute: category Removed attribute: category Removed attribute: category