Note Contents Map:
Elements object (Element object)
- To manipulate the element object, first obtain the element (obtained using the corresponding method in document)
- The method inside the element
- GetAttribute ("Property name"): Gets the value inside the property
<HTML><Body> <inputtype= "text"ID= "a"class= "haha"value= "Name"></Body> <Scripttype= "Text/javascript"> varINPUT1=document.getElementById ("a"); alert (Input1.value); //namealert (Input1.getattribute ("value")); //namealert (Input1.class); //Undefined Note: Class is not worth the reason: class is a keyword. So you can only use GetAttribute to take class values.alert (Input1.getattribute ("class")); //hahaalert (input1.id); //aalert (Input1.getattribute ("ID")); //a</Script></HTML>
- SetAttribute ("name", "value"): Setting properties
- Removeattribut (name): Delete attribute
<HTML><Body> <inputtype= "text"ID= "a"value= "Name"></Body> <Scripttype= "Text/javascript"> varINPUT1=document.getElementById ("a"); Alert (Input1.getattribute ("class")); //NULLInput1.setattribute ("class","haha"); //set the Class property and give the value hahaalert (Input1.getattribute ("class")); //hahaInput1.removeattribute ("class"); //Delete Attribute classalert (Input1.getattribute ("class")); //NULLInput1.removeattribute ("value"); //Delete property valuealert (Input1.getattribute ("value")); //Name Note: removeattribute cannot delete value! </Script></HTML>
- Get the sub-label below the label
- Use attribute ChildNodes, but this property is poorly compatible
html><Body> <ulID= "Ulid"> <Li>Aaaa</Li> <Li>bbbb</Li> <Li>Cccc</Li> </ul></Body> <Scripttype= "Text/javascript"> varUl11=document.getElementById ("Ulid"); varLis=Ul11.childnodes; alert (lis.length); //Under ie the result is 3, under Firefox is 7</Script></HTML>
So, the only effective way to get a label on the face tag is to use the getElementsByTagName method. The method return value is a collection
<HTML><Body> <ulID= "Ulid"> <Li>Aaaa</Li> <Li>bbbb</Li> <Li>Cccc</Li> </ul></Body> <Scripttype= "Text/javascript"> varUl11=document.getElementById ("Ulid"); varLis=Ul11.getelementsbytagname ("Li"); alert (lis.length); //3</Script></HTML>
Second, Node object
V. Basic JavaScript &dom (ii)