To access the specified node:
Getelementsbyname ():
<ptml> <pead> <title>dom Technology </title> </pead> <body> <form method= "Post action=" document.cgi "> <fieldset> <legend> Choose the color you like!" </legend> <input type= "Radio" name= "Color" value= "Red"/>red <input "type=" "Radio" Color "name=" GRE En "/>green <input type=" Radio "name=" Color "value=" Blue "/>blue </fieldset> <input type=" Submit "Val Ue= "Submit" > </form> <script language= "JavaScript" > var oradios=document.getelementsbyname ("Color"); Alert (Oradios[0].getattribute ("value")); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<ptml> <pead> <title>dom Technology </title> </pead> <body> <form method= "Post action=" document.cgi "> <fieldset> <legend> Choose the color you like!" </legend> <input type= "Radio" name= "Color" value= "Red"/>red <input "type=" "Radio" Color "name=" GRE En "/>green <input type=" Radio "name=" Color "value=" Blue "/>blue </fieldset> <input type=" Submit "Val Ue= "Submit" > </form> <script language= "JavaScript" > var oradios=document.getelementsbyname ("Color"); Alert (Oradios[0].getattribute ("value")); </script> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
getElementById ():
<ptml> <pead> <title> </title> <script type= "Text/javascript" > Function GetValue () {VA R Odiv1=document.getelementbyid ("Div1"); odiv1.innertext= "hello!";} </script> </pead> <body onload= "GetValue ()" > <div id= "div1" ></div> </body> </p Tml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<ptml> <pead> <title> </title> <script type= "Text/javascript" > Function GetValue () { var Odiv1=document.getelementbyid ("Div1"); odiv1.innertext= "hello!";} </script> </pead> <body onload= "GetValue ()" > <div id= "div1" ></div> </body> </p Tml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
CreateElement ():
<ptml> <pead> <title> Create node </title> </pead> <body onload= "Createm ()" > </body> ; </ptml> <script language= "JavaScript" > Function Createm () {var op=document.createelement ("P"); var otext=document.createtextnode ("Hello!") "); Op.appendchild (Otext); Document.body.appendChild (OP); } </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<ptml> <pead> <title> Create node </title> </pead> <body onload= "Createm ()" > </body> ; </ptml> <script language= "JavaScript" > Function Createm () {var op=document.createelement ("P"); var otext=document.createtextnode ("Hello!") "); Op.appendchild (Otext); Document.body.appendChild (OP); } </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
RemoveChild ():
<ptml> <pead> <title> Delete node </title> <script language= "JavaScript" > Function Removem () {VA R op=document.body.getelementsbytagname ("P") [0]; Document.body.removeChild (OP); } </script> </pead> <body onload= "Removem ()" > <p> Hello! </p> <p>hello world! </p> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
<ptml> <pead> <title> Delete node </title> <script language= "JavaScript" > Function Removem () {VA R op=document.body.getelementsbytagname ("P") [0]; Document.body.removeChild (OP); } </script> </pead> <body onload= "Removem ()" > <p> Hello! </p> <p>hello world! </p> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Current 1/3 page
123 Next read the full text