JavaScript (1)
The first time I saw javascript, I saw the familiar "Java", the original is a lie, Li Ghost is not Li Kui ah =. however, finding this thing is particularly useful, and it's much simpler than java, just a lightweight scripting language that is used primarily for HTML and the Web. In the beginning, those who tried to write a bunch of code to complete the function, as long as the use of JavaScript has become very simple.
Because I have not used this thing for a long time, I intend to follow W3school to learn one side, in order to learn jquery and Ajax to lay the groundwork for the Future.
1. Output in HTML page
JS can be written directly to the HTML output stream and output on the page, but note that document.write can only be used in the HTML output stream and will overwrite the entire document if it is used after the document is Loaded.
1 <Body>2 <Scripttype= "text/javascript">3 document.write ("JavaScript is a scripting language");4 document.write ("<br/>");5 document.write ("It doesn't matter with Java =. =");6 </Script>7 </Body>
2. Responding to Events
JavaScript can react to events, such as clicking a Button.
<!DOCTYPE HTML><HTML><Body><Buttontype= "button"onclick= "alert (' let you point it out!!! ')">Click here</Button></Body></HTML>
3. Change HTML content
This feature is more commonly used, document.getElementById ("some ID"), which is defined in the HTML dom, and the DOM is a formal standard for accessing HTML Elements.
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Change the elements in the HTML</title></Head><Body><PID= "demo">I'm Learning Javascript.</P><Scripttype= "text/javascript"> functionTest () {x=document.getElementById ("Demo"); //find an element based on the id attributex.innerhtml= "I don't know how to learn! "; //changing elements }</Script><Buttontype= "button"onclick= "test ()">Come on, Me.</Button></Body></HTML>
4. Changing the style of HTML
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Change the elements in the HTML</title></Head><Body><PID= "demo">I'm Learning Javascript.</P><Scripttype= "text/javascript"> functionTest () {x=document.getElementById ("Demo"); //find an element based on the id attributeX.style.color= "#ff0000" //changing elements }</Script><Buttontype= "button"onclick= "test ()">Come on, Me.</Button></Body></HTML>
5. Verify the input
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Validate input</title></Head><Body><P>Please enter a number. If the input value is not a number, a prompt box prompts "input error".</P><inputID= "demo"type= "text"><BR/><Scripttype= "text/javascript"> functionTest () {varx=document.getElementById ("Demo"). value; if(x==""||IsNaN (x)) {alert ("input error! "); } }</Script><Buttontype= "button"onclick= "test ()">Come on, Me.</Button></Body></HTML>
JavaScript (1)