JavaScript Learning Notes

Source: Internet
Author: User

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><title>Beginner's Tutorial (runoob.com)</title><Script>functiondisplaydate () {document.getElementById ("Demo"). InnerHTML=Date (); First get ID is the object of the demo, in the re-assigned to the content of the object}</Script></Head><Body><H1>My first JavaScript program</H1><PID= "Demo">This is a paragraph</P><Buttontype= "button"onclick= "displaydate ()">Show Date</Button></Body></HTML>
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title>Beginner's Tutorial (runoob.com)</title> </Head><Body>    <Script>functionchangeimage () {element=document.getElementById ('MyImage')    if(Element.src.match ("Bulbon")//The default src is src= "/images/pic_bulboff", and when clicked, Match () determines if SRC contains a string Bulbon {element.src="/images/pic_bulboff.gif"; }    Else{element.src="/images/pic_bulbon.gif"; }}</Script><imgID= "MyImage"onclick= "Changeimage ()"src= "/images/pic_bulboff.gif"width= "+"Height= " the"><P>Tap the light bulb to turn the lamp on or off</P>    </Body></HTML>
X=document.getelementbyid ("demo")  //Find element x.style.color= "#ff0000";           Change Style
function MyFunction () {    var X=document.getelementbyid ("Demo"). Value;    Gets the ID of the demo object inside your value    if (x== "" | | IsNaN (x))    {        alert ("Not a number");}    }

Note the Var X=document.getelementbyid ("Demo"). Value; If there is a box, such as the input tag with value

var X=document.getelementbyid ("Demo"). InnerHTML no box, such as <p> tags

var person={firstname: "John", LastName: "Doe", id:5566}; Creating objects
Person.lastname; Two ways to access the object properties person["LastName"];
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Script>functionValidateform () {varx=document.forms["MyForm"]["fname"].value; Determine if the value of the fname in the form existsif(x== NULL ||x== "") {alert ("you need to enter a name. "); return false; }}</Script></Head><Body><formname= "MyForm"Action= "demo_form.php"onsubmit= "return Validateform ()"Method= "POST">Name:<inputtype= "text"name= "FName"><inputtype= "Submit"value= "Submit"></form></Body></HTML>
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"></Head><Body><formAction= "demo_form.php"Method= "POST">//Auto-Verify whether the form is empty or low version browser not supported  <inputtype= "text"name= "FName"Required= "Required">  <inputtype= "Submit"value= "Submit"></form><P>Click the Submit button, if the input box is empty, the browser will prompt the error message.</P></Body></HTML>

JavaScript Learning Notes

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.