The semester college opened JS, because do not like the style of the teacher, the course of two months can be said almost no listen. But JS still has to learn, from YouTube to find a playlist self-study. Let's write down what I've learned.
JS variables, functions, basic control types (If,switch, various loops) are similar to C + + is not nonsense. With the foundation of C + + I think that learning JS Basic is to learn it and other languages are not the same things, at present it seems basically two: 1. Syntax 2. and HTML interaction (such as Form,id,checkbox,radio);
From the recent I saved the HTML file to get into the details:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8"/>5 <title>My00</title>6 <Scripttype= "Text/javascript">7 functionCheck () {8 varun=document.getElementById ('id_1'). Value;9 varPW=document.getElementById ('id_2'). Value;Ten varYB=document.getElementById ('Id_3'). checked; One varNB=document.getElementById ('Id_4'). checked; A varCB=document.getElementById ('id_5'). checked; - varCF=document.getElementById ('Id_6'). checked; - varCTT=document.getElementById ('id_7'). checked; the varCT=document.getElementById ('Id_8'). checked; - if(UN=="")||(PW=="")||(YB==false &&NB==false)||(CB==false &&CF==false &&CTT==false &&CT==false)){ - Alert ("Fill in all the fields please!"); - return false; + } - Else{ + return true; A } at } - </Script> - </Head> - <Body> - <formAction= "Http://www.baidu.com"Method= "Get"onsubmit= "return check ()"> -User Name:<inputtype= "text"value=""ID= "Id_1"/><BR> inPassword:<inputtype= "Password"value=""ID= "Id_2"/><BR> - <P>Does want to keep it secret?</P> to <inputtype= "Radio"name= "CHECKB"value= "Yes"ID= "Id_3"/>Yes<BR> + <inputtype= "Radio"name= "CHECKB"value= "No"ID= "Id_4"/>No<BR> - <P>What kinds's Sports do you like?</P> the <inputtype= "checkbox"name= "MyCheckBox"value= "Basketball"ID= "Id_5">Basketball<BR> * <inputtype= "checkbox"name= "MyCheckBox"value= "Football"ID= "Id_6">Football<BR> $ <inputtype= "checkbox"name= "MyCheckBox"value= "Table tennis"ID= "Id_7">Table Tennis<BR>Panax Notoginseng <inputtype= "checkbox"name= "MyCheckBox"value= "Tennis"ID= "Id_8">Tennis<BR> - <inputtype= "Submit"value= "Login"/><BR> the </form> + </Body> A </HTML>
From the body to see this HTML file is mainly form (form), JS do is to ensure that the user filled out all the information (more specifically, to ensure that users fill out the user Name,password, to ensure that a radio is selected as a single box, Make sure that at least one checkbox is selected and that is the check box. JS implementation of the so-called "ensure" the way is if the statement, you see the IF statement between <script></script> will feel very messy, I finished writing this line of code also feel, but I did not think so when I wrote. Basically the IF statement is null for the 1.user name of 2.password is 3. Two radiobutton are not selected 4. No checkbox is checked, and in four cases return false,else is true;
And the return value is the check () function, when to call the check () function? It is not difficult to find the onsubmit event that is a form tag. Okay, back to the HTML again. In this document, the body is a form tag, the form is four types of input tags, their type is 1.text; 2.radio; 3.checkbox; 4.submit; The text does not say much to let the user enter some text, Radio is a radio box, look at 31 rows and 32 rows, the Name property of both lines is "checkb", which indicates that the two radio boxes are a group that the user can only choose from. The checkbox and radio are similar, the only difference is that the checkbox can be selected by the user. The final submit is a button that represents the submission form, and when the user presses the button, the "onsubmit" of the form tag is triggered and the return value of the check () function of the return JS starts. Once the check () function discovers that the user has filled out the form as required, the return value of the check () function is true, and the action of the form label is executed (here I let the page jump to Baidu, but the real world does not play with it). Finally, the "method" property of the form tag here, the general method can choose "Get" and "post" the two values, post more secure point. If you feel big head, ignore it, now remember can fill "get" and "post" OK;
This is the Web page in chrome loaded, and one point is in the JS check () function has a few variables, UN on behalf of user Name,ps password, which used the. Value property, the other variables are used. Checked property. For example, if the user name is not filled in, then value is empty, and un== "" will return false in the If of the check () function, so that the action of form forms will not be executed.
Javasript What have I learned so far Part-1