A. js attribute operation summary
We are in the front-end development process will encounter a variety of operations, which will involve the operation of properties, I will give you a few of the most common JS properties of the operation, of course, I will not take the example to explain, just briefly said usage.
1. Common attribute operation: Obj.setattribute (name of property)
2.class operation: Obj.classname= "";
3.img operation of SRC: imgobj.src= "";
4.input value operation: Inputobj.value
5. Other
Two. js attribute operation should pay attention to the problem
Special characters not allowed in 1.JS
2 Several compatibility issues: JS can not directly through the obj.style.float properties, through IE (stylefloat), non-IE (cssfloat) solution
three, instance (set Div's properties)
SetAttribute Method:
The code is as follows |
Copy Code |
var a=document.createelement ("div"); Create a new div A.id= "Div1"; Name the newly added Div A.style.setattribute ("ZIndex", 2); Set DIV Stacking order A.style.setattribute ("TextAlign", dalign); Alignment method A.style.setattribute ("Border", "#e6e7e8 1px solid"); Border color A.style.width=divwidth; Div width A.style.height=dheight; div height A.setattribute ("position", "absolute"); A.style.backgroundcolor=dbgcolor; Div background A.setattribute ("Z-index", "2"); div stacking Order A.style.top = divtop+ "px"; Div Top Margin A.style.left = divleft+ "px"; Div left margin A.setattribute ("InnerHTML", info10[0].firstchild.data+ "<br>" +info11[0].firstchild.data); Document.body.appendChild (a); New Div End Hide Div:document.getElementById ("Ah"). style.display= "None"//block appears document.getElementById ("Ah"). Style.disabled= "true" document.getElementById ("Ah"). Style.readonly= "true" |
According to the above example summary
1: Traversal of object properties can be traversed by (Var attrname in obj)
2: To determine whether an object has a property that can be judged by attrname in obj, if no this property returns undefined, an object can add an attribute to an object, but does not set a value for this property
3: To determine whether a property of an object is defined in its own constructor rather than inherited, it can be obj.hasownproperty by function (attrname).
4: Determine if a property can be traversed through the for/in way through Obj.propertyinenumerable (Attrname), but the attribute must be derived from a way that is not inherited.