JS Basic Knowledge 2

Source: Internet
Author: User

First, the Prompt box 1. Pop-up Alert box alert ();   Window.alert (); Window Windows 2. Console output Console.log () 3. Documents Print Document document document.write (); 1. Which of the following JavaScript syntax formats is correct () A.                             echo "I enjoy JavaScript"; B document.write (I enjoy JavaScript) C.   Response.Write ("I enjoy JavaScript"); D  Alert ("I enjoy JavaScript"); Second, variable Java Var aa:int = 10; var num = 10; Letter _ $ begins with Var dd=100,ee=100 declares multiple variables comma-separated by 1.  In JavaScript, which of the following declaration variable statements is incorrect?   A, var aa; B, Var bb=3;  Cc= ' good ';  C, var dd = EE = 100;  D, var ff=3, gg= ' he ' s good '; Events three elements event source is triggered by the object noun event verb onclick onmouseover onmouseout event handler put the event source in the function.      event = function () {statement;} Entry function: window.onload = function () {} Four, inline<Divonclick= "alert (one)">Inline type outer chain type<Scripttype= "Text/javascript"src= "Xx.js"></Script> v. Data type number string Boolean null undefined 1.2 function function: The function is event-driven or A reusable code block that executes when it is invoked.  The four major inventions of the paper-making powder guide needle printing the Declaration function of the 1.2.1 function uses the same variables as the variable, you need to declare the 1.2.2 Custom Function fun () {alert ("I am a custom Function")}fun ();  The function does not call, itself does not execute the 1.2.3 function Direct Amount declaration var fun1 = function () {Alert ("Direct volume Declaration")}fun1 (); You also need to call 1.2.4 using the Function keyword to declare var fun2 = new Function ("var a = 10; var B = 20; Alert (A+B) "); Fun2 (); 1.2.5 Variable declaration promotes what is a variable boost 1 function fun () {2 console.log (num); 3 var num = 20;4} equals- --5 function Fun () {6 var num;7 console.log (num); 8 num = 20;9} inside the function body, declaring the variable will elevate the declaration to the top of the function body. Only the variable declaration is lifted, and no value is assigned.    var a = 18;f1 (); function F1 () {var b=9;    Console.log (a);    Console.log (b); var a = ' 123 ';} The result is: the undefined 9 1.2.6 function parameter arguments is a stored function that passed over the argument JavaScript creates a arguments object instance within the function while creating the function. The arguments object is only available when the function starts. The arguments object of a function is not an array and accesses a single parameter in the same way as an array element arguments the length of the object is determined by the number of arguments rather than the number of parameters <Script>    functionfn (A, b) {console.log (fn.length);//get the number of formal parameters that are functions        //console.log (arguments);Console.log (arguments.length);//The number of arguments is obtained        if(Fn.length==arguments.length) {Console.log (a+b); }        Else{console.error ("Sorry, your parameters do not match, the correct number of parameters is:" +fn.length); }        //Console.log (a+b);} fn (1,2); FN (1,2,3);</Script>  Var A = ten, B = 20;  The equivalent Var a = 10; var B = 20;1.3 Case Mouse display code: var box = document.getElementById ("box"); function fn (LIID,BG) {//package function parameter passed var obj =    document.getElementById (LIID);    Obj.onmouseover = function () {box.style.backgroundImage = BG; }}FN ("li01", "url (images/01big.jpg)"); Argument fn ("li02", "url (images/02big.jpg)"), FN ("li03", "url (images/03big.jpg)"), FN ("li04", "url (images/04big.jpg)"); FN ("li05", "url (images/05big.jpg)"); 1.4 returns value return definition: A function is actually a calculation process, and the result after the calculation is the return value. Defines the return value of a function: sets the return value with return inside the function, and a function can have only one return value. Also, terminate the execution of the code. All custom functions do not return a value by default, and do not wrap function $ (ID) {return document.getElementById (ID) after return;} $ ("demo"). Style.backgroundcolor = ' Purple '; $ ("test"). Style.backgroundcolor = "Blue"; 1. What is the result of the following code execution? Please analyze why?          1 var total=10;1 var number = Square (5), 2 alert (number), 3 function square (n) {4 total = n*n;5 Return total;6} result is 251.5 arithmetic operator +-*/% ^ = 2 5%2 = = 1 2%5 = = 2 2^3 A +     + + + Rear-facing  Each self-add 1 after the first operation after the ++a + + + each self plus 1 before adding the Operation 1. Analyze the code to get the correct results. 1 var a=10, b=20, c=30;2 ++a;3 a++;4 e=++a+ (++b) + (c + +) +a++;5 alert (e), 771.6-piece statement (IF) if (conditional expression  {statement;}  if () {}else {} if () else if () {} else if () {} else {}1.7 Get focus out of focus event we've learned the onclick before. Click onmouseover onmouseout '   Get Focus: onfocus FAO ~ gram dead loses focus: Onblur no Len ~ ~<Script>window.onload= function(){        vartxt=document.getElementById ("txt"); Txt.onfocus= function(){ //Get Focus            //alert ("Get Focus");            //when should I empty it?            //The user does not enter the time, the first time users use           //if the text inside the input is please enter ... Indicates that the user has not used, should be emptied            if(Txt.value== "Please enter ...") {Txt.value= ""; Txt.style.color= "#333"; }} Txt.onblur= function(){ //Lose Focus            //alert ("Lost Focus");            //When do we restore it?             //when the value of input is empty, we recover            if(Txt.value== "") {Txt.value= "Please enter ..."; Txt.style.color= "#ccc"; }        }    }</Script>1.8 This (own) refers to itself as this is primarily referred to as the caller of the event.    ClassName class Name $ ("result"). ClassName = "wrong"; InnerHTML replace the contents of the box with the text tag. Form Replacement Input.value IsNaN Nan is not a number      IS is not a number isNaN ("12") if the inside is not a number return true otherwise return false1.9 properties and methods the external properties of the iron of the 5.5-inch plastic of the phone black Property the color of the phone is black.     Iphone.color = "Red";     attribute to the value must be an equal sign method: Mobile phone to send text messages to play games chat QQ Watch movie verbs can do Iphone.tel ();  Methods and properties differ: methods are all enclosed in parentheses.    IsNaN ();   The verb method gives the value: IsNaN ("value"), the 1.9.1 form automatically obtains the focus Txt.focus (); Method onfocus Event<!DOCTYPE HTML><HTML><HeadLang= "en">    <MetaCharSet= "UTF-8">    <title></title>    <Script>window.onload= function(){            vartxt=document.getElementById ("txt"); Txt.focus (); //Get focus automatically        }    </Script></Head><Body>automatically get focus:<inputtype= "text"ID= "txt"/></Body></HTML>1.9.2 mouse over select form sele.onmouseover = function () {this.select ();//Select} method Select () Choose function 1.10 for loop life a loop i+=3 I=i+3 1.11 getElementsByTagName () Get a class of tags before we can get a box by ID get getElementById () only to a box we want to get some kind of tag like all  Div Li Spangetelementsbytagname (); Many of these are complex numbers and many get a pseudo-array. Lis Array lis[index number] one

JS Basics 2

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.