Third, JS base statement1, JS call, can be placed in any place, it is recommended to put the HTML end(1) Call JS file<script type= "Css/javascript" src= "Js/web.js" ></script>(2) Direct writing<script type= "Css/javascript" >alert ("Hello");</script>2. Variable control statementsA, variable definition, weakly typed language, no variable typevar d = new Date ();var a = 1;var m = 0, n = 0;var cars =["1", "2", "3";//structure as followsvar names=["Zhang San", "John Doe"];For (var i =0;i<names.length;i++) {if (names[i]== "Zhang San") {alert (names[i]);} }B. Define methods and call methods:(1) method without parameterssum ();//Method callfunction sum () {//define methodvar n=0,sum=0;While (n<10) {sum=sum+n;n++}alert ("for" + sum);}(2) method with parameterssum (80,100);//Method callfunction sum (n,m) {//Definition methodvar n,sum=0;While (n<m) {sum=sum+n;n++}alert ("for" + sum);}(3) method with parameter and return valueal (3);//Call bonus sumfunction Pro (m) {//define method, ask m! m factorialvar n=1,pro=1;While (n<=m) {pro=pro*n;n++}return Pro;//returns value}function Al (n) {//factorial sumvar sum=0;For (i=1; I <=n;i++) {sum=sum +pro (i)}alert (sum);}C, Event, event is written in the attribute of the tag, "" Inside the name of the JS method, "" in the string Plus 'onclick= ""//Click eventondblclick= ""//double-click eventonload= ""//load time, generally placed on the Body propertyonfocus= ""//Aggregation Focusonblur= ""//Lose Focusonmousedown= ""//mouse point downonmouseover= ""//mouse hoveronmouseout= ""//mouse move off d, JS input and OutputInput:prompt ();Output:alert ("Hello");doucument.write ("Hello"); E.document Object Method (HTML DOM style object)Close ()//closes the output stream opened with the Document.open () method and displays the selected data. getElementById ()//Returns a reference to the first object that owns the specified ID. Getelementsbyname ()//Returns a collection of objects with the specified name. getElementsByTagName ()//Returns a collection of objects with the specified label name. Open ()//Open a stream to collect the output from any document.write () or Document.writeln () method. Write ()//write an HTML expression or JavaScript code to the document. Writeln ()//is equivalent to the Write () method, unlike writing a newline character after each expression. Example: Input tag focus and zooming triggering method<input class= "RG" name= "username" type= "text" placeholder= "Please set user name" Onfocus= "ShowMsg ()"onblur= "hiddenmsg ()" ><div id= "MSG" style= "width:120px; float:right; display:none;" ><span> cannot be changed after Setup </span></div><script>//Call script, you can modify CSS style by JSfunction ShowMsg () {document.getElementById ("MSG"). style.display= "Block";}function hiddenmsg () {document.getElementById ("MSG"). style.display= "None";} </script>F.jqueryJQuery is a JavaScript library. JQuery greatly simplifies JavaScript programming. JQuery is easy to learn. Example: Using jquery to write a hidden JS statement<script src= "/jquery/jquery-1.11.1.min.js" >//first calls jquery's JS library, similar to the package in Java</script><script>$ (document). Ready (function () {$ ("P"). Click event (function () {//p tag)$ (this). Hide (); P Tag Hide });});</script>
Third, JS Foundation