First, JS gets the tags in the Web page, JS through the System objectDocumentthe 3 Get methods
Method return value
document.getElementById ("btn") The label has only one
Document.getelementsbyname () A set of labels with the same name value
document.getElementsByTagName ("a") get all the hyperlink tags on the page
Second, the layer above display content
$ ("div"). InnerHTML ("Set print content");
Application scenario: Display different prompts (user login, information registration, etc.) through conditional judgment
Three, JS event loading mode
<script type= "Text/javascript" >
<!--Bind an order and click Events-
document.getElementById ("Btn"). onclick= event handler; */
/*function Listinit () {
Alert ("11");
}
/* Window.document.onload=function () {Cannot implement load
Alert ("11");
}*/
The first form of a notation
/*window.onload=function () {
alert (3232);
Listinit ();
alert (3232);
}*/
The second method of
/* Window.onload=listinit (); */
function $ (ID) {
return document.getElementById (ID);
}
Load the page first, then load the button to listen for events
Window.onload=function () {
Alert ("Submit Information");
$ ("btnsubmit"). Onclick=function () {
Alert ("Submit success");
}
}
</script>
Iv. get the specified label, get the label content
<!-- get labels by ID--
function $ (ID) {
return document. getElementById (ID);
}
<!-- gets the label from the class selector--
function $$ (name) {
return document. Getelementsbyname (name);
}
$ ("BTN"). onclick=function() {
document. Forms [0].submit ();
}
<!--Get labels by ID--
function$(ID) {
returnDocument. getElementById (ID);
}
<!--gets the label from the class selector--
function$$(name) {
returnDocument. Getelementsbyname (name);
}
$("BTN").onclick=function() {
Document.Forms[0].submit ();
}
/* get the Content ID as div tag */
$("Div1"). Value ();
/*set the value for ID DIV1 */
$("Div1").InnerHTML("fill in the value of the set worth ");
/*Select an array of elements based on the class selector, usually a check box */
varStr="";
varVarm=$$(". Class");
for(varI= 0;I<Varm. length;I++){
if($$(". Class")[I].checked){
Str+=$$(". Class")[I].value ();
}
}
JS Basic operation