Python's Web front section:
Javascript
A. What is JavaScript?
JavaScript is a programming language, the browser has built-in JavaScript interpreter, so in the browser according to the JavaScript language rules to write the corresponding code, the browser can explain and make corresponding processing.
Two. JavaScript Authoring:
1. js code exists in the form:
Mode one: Introduce JS file:
1 < type= "Text/javascript" src= "js file"></ Script>
Mode two: Directly edit the JS code
1 < type= "Text/javascript">2 JS code content 3 </ Script >
2. JS Code Placement Location:
(1) between
Since the HTML file is loaded by the browser from top to bottom, you can ensure that the JS code is loaded first.
If the JS code response delay, the user can not see the page for a long time, greatly affected the user experience.
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scripttype= "Text/javascript">7 JS Code content8 </Script>9 </Head>Ten <Body> One A </Body> - </HTML>
(2) placed in the <body></body> bottom of the HTML file
When the JS code is placed in the <body> bottom, even if the JS code response delay, users can see the Web page, but the JS effect is slightly slower, the impact on the user experience will not be great.
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title></title>6 <Scriptsrc= "https://www.gstatic.com/og/_/js/k=og.og2.en_US.iF4jnkQuaf0.O/rt=j/t=zcms/m=def/exm=in,fot/d=1/ed=1/rs= Aa2yrtv5-poc4ks9gtgrdy2ywuwisqz7-q "></Script>7 <Script>8 Alert (JS code content);9 </Script>Ten </Head> One <Body> A - </Body> - </HTML>
3. The comments in the JS code:
As with other languages to provide readability of the code, JS annotations are divided into two types: single-line comments and multiline comments.
(1) Single-line comment:
Start with//
1 <Scriptsrc= "https://www.gstatic.com/og/_/js/k=og.og2.en_US.iF4jnkQuaf0.O/rt=j/t=zcms/m=def/exm=in,fot/d=1/ed=1/rs= Aa2yrtv5-poc4ks9gtgrdy2ywuwisqz7-q ">2 //src Specifies the source link of the JS code3 </Script>4 <Script>5 //Alert output JS code content6 Alert (JS code content);7 </Script>
(2) Multi-line Comment:
Start with/* and end with */.
1 <Scriptsrc= "https://www.gstatic.com/og/_/js/k=og.og2.en_US.iF4jnkQuaf0.O/rt=j/t=zcms/m=def/exm=in,fot/d=1/ed=1/rs= Aa2yrtv5-poc4ks9gtgrdy2ywuwisqz7-q ">2 /*3 src Specifies the source link of the JS code4 Alert output JS code content5 */6 </Script>7 <Script>8 Alert (JS code content);9 </Script>
Three. JavaScript variables
Like algebra, JavaScript variables can be used to hold values (such as x=2) and expressions (such as z=x+y).
Variables can use short names (such as x and y), or they can use better descriptive names (such as age, Sum, totalvolume).
-
- Variables must start with a letter
- Variables can also start with the $ and _ symbols (although we do not recommend this)
- Variable names are case sensitive (Y and y are different variables)
JS variables are divided into local variables and global variables:
Note: Both JavaScript statements and JavaScript variables are case-sensitive.
Python 15th day