HTML DOM setAttributeNode() ·½·¨
ʵÀý
ÉèÖà header ÔªËØµÄ class ÊôÐԽڵ㣺
var atr=document.createAttribute("class"); atr.nodeValue="democlass"; document.getElementsByTagName("H1")[0].setAttributeNode(atr);
ÉèÖÃÊôÐÔ½Úµã֮ǰ£º
Hello World
ÉèÖÃÊôÐÔ½ÚµãÖ®ºó£º
Hello World
¶¨ÒåºÍÓ÷¨
setAttributeNode() ·½·¨ÏòÔªËØÖÐÌí¼ÓÖ¸¶¨µÄÊôÐԽڵ㡣
Èç¹ûÕâ¸öÖ¸¶¨µÄÊôÐÔÒÑ´æÔÚ£¬Ôò´Ë·½·¨»áÌæ»»Ëü¡£
ä¯ÀÀÆ÷Ö§³Ö
IE | Firefox | Chrome | Safari | Opera |
---|---|---|---|---|
ËùÓÐÖ÷Á÷ä¯ÀÀÆ÷¾ùÖ§³Ö setAttributeNode() ·½·¨¡£
Óï·¨
element.setAttributeNode(attributenode)
²ÎÊý
²ÎÊý | ÀàÐÍ | ÃèÊö |
---|---|---|
attributenode | Attr ¶ÔÏó | ±ØÐè¡£ÄúÏ£ÍûÌí¼ÓµÄÊôÐԽڵ㡣 |
·µ»ØÖµ
ÀàÐÍ | ÃèÊö |
---|---|
Attr ¶ÔÏó¡£ | ±»Ìæ»»µÄÊôÐԽڵ㣬Èç¹ûÓУ¬·ñÔò·µ»Ø null¡£ |
¼¼Êõϸ½Ú
DOM °æ±¾ | Core Level 1 Element Object |