JS Basic operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.