1.ele.getattribute (AttributeName);
Returns the specified property value of the element, or null if the element does not have the attribute
2.ele.setattribute (Attributename,value);
Sets the value of the attribute for the element and, if there is no attribute, creates the property and assigns a value
3. The settings for the properties in IE 7 and earlier versions should use a different name, in order to be compatible with IE
<Script>Dom=(function(){ varfixattr={tabindex:'TabIndex', ReadOnly:'readOnly', ' for':'htmlfor', 'class':'ClassName', MaxLength:'MaxLength', cellspacing:'cellspacing', cellpadding:'cellpadding', rowspan:'RowSpan', colspan:'ColSpan', Usemap:'Usemap', frameborder:'frameborder', contenteditable:'contenteditable' }, //analog settings attribute,Div=Document.createelement ('Div'); Div.setattribute ('class','T'); varsupportsetattr=Div.classname=== 'T'; return{setAttr:function(el, name, Val) {El.setattribute (supportsetattr?name: (Fixattr[name]||name), Val); }, GetAttr:function(el, name) {returnEl.getattribute (supportsetattr?name: (Fixattr[name]||name)); } } })(); Window.onload=function(){ varmydiv=document.getElementById ("D1"); Dom.setattr (Mydiv,'class', 'BG'); } </Script>
In IE 7 and earlier, SetAttribute (' class ', ' fo ') can add class= ' fo ' to the element.
GetAttribute (' class '), can return fo value, but the class added for the element does not work, should be set for IE 7 and earlier classes with ClassName, instead of class
4.
GetAttribute (AttributeName), not only can get the default attribute value of the element, but also can get the custom attribute value ele.attributename or ele[' attributename ' can only get the attribute value that the element default exists
5.
var node = Ele.getattributenode (attributename) Gets the attribute node Console.log (node);//name=value form Console.log (node.name); Console.log (Node.value);
<Body> <PID= "P1"CustomData= "PMX">Ppp</P> <Script> varP=document.getElementById ("P1"); varPnode=P.getattributenode ("CustomData"); Console.log (Pnode)</Script></Body>
6.ownerElement returns the element attached to the attribute node
Grammar:
Attrobj.ownerelement
JS's setattribute and GetAttribute