Javascrip Essay 1

Source: Internet
Author: User

    • IsNaN: Indicates that a value is not a number
    • A backslash is used to wrap lines of code in a text string;
    • In computer programs, variables that are not valued are often declared. A variable that is not declared with a value, whose value is actually undefined. After executing the following statement, the value of the variable carname will be undefined, such as: Var carname;
1<script>2 3 functionmyFunction ()4 {5X=document.getelementbyid ("demo");//Find Element6X.innerhtml= "Hello javascript!";//Change Content7 }8 9 Ten functionchangeimage () One { AElement=document.getelementbyid (' MyImage ') -     if(Element.src.match ("Bulbon")) - { theElement.src= "/i/eg_bulboff.gif"; - } -     Else - { +Element.src= "/i/eg_bulbon.gif"; - } + } A</script> at  -

Create An array named cars:

1 var New Array (); 2 cars[0] = "Audi"; 3 cars[1] = "BMW"; 4 cars[2] = "Volvo"; 5 or:varnew Array ("Audi", "BMW", "Volvo");

JavaScript objects

Objects are separated by curly braces . Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). attributes are separated by commas :

1 var person = {firstname: "Bill", LastName: "Gates", id:5566}; 2 3 var person = {4     firstname: "Bill",5     lastname  : "Gates" , 6     ID        :  55667 };

Access method: name = Person.lastname; Name = person["LastName"];

Declaring variable types:
1 var carname=new  String; 2 var x=      new number ; 3 var y=      new  Boolean; 4 var cars=   new  Array; 5 var New Object;

Method of the object:
1 var txt = "Hello"; 2 3 txt.length=5; 4 Txt.indexof (); 5 txt.replace (); 6 Txt.search (); 7 txt.touppercase ();

To change the HTML style:
1 <p id= "P2" >hello world!</p>23 <script>4 document.getElementById ("P2"). style.color= "Blue"; 5 </script>

Mouse events:
    • onload: Events when the browser is loaded
    • onclick: An event when a tag is clicked
    • onchange: Events are often combined with validation of input fields, such as input
    • onmousedown, onmouseup , and onclick form all parts of the mouse click event. First, when the mouse button is clicked, the OnMouseDown event is triggered, and when the mouse button is released, the OnMouseUp event is triggered, and the onclick event is triggered when the mouse click is completed.
    • onfocus Changes the background color when the input field gets focus.
1 <Script>2 functionmyFunction ()3 {4     varx=document.getElementById ("fname");5 X.value=x.value.touppercase ();6 }7 </Script>8 9Please enter English characters:<inputtype= "text"ID= "FName"onchange= "myFunction ()">Ten <P>When you leave the input field, the function that converts the input text to uppercase is triggered.</P>
    • onmouseover,onmouseout: When the mouse moves over the HTML event and comes out when the factory generates events
1 <Divonmouseover= "MOver (this)"onmouseout= "Mout (this)"style= "Width:120px;height:20px;padding:40px;color: #ffffff;">Move the mouse over the top</Div>2 3 <Script>4 functionmOver (obj)5 {6 obj.innerhtml="Thanks"7 }8 9 functionmout (obj)Ten { One obj.innerhtml="move the mouse over the top" A } - </Script>

Delete and create tags with javacrip:
1 <DivID= "Div1">2 <PID= "P1">This is a paragraph</P>3 <PID= "P2">This is another paragraph</P>4 </Div>5 6 <Script>7 //Create a label8 varpara=Document.createelement ("P");9 varnode=document.createTextNode ("This is a new paragraph. ");Ten para.appendchild (node); One varelement=document.getElementById ("Div1"); A Element.appendchild (para); -  - //Delete the label (you need to find the parent class label and then delete it with RemoveChild ()) the varParent=document.getElementById ("Div1"); - var Child=document.getElementById ("P1"); - Parent.removechild (child); -  + </Script>

Javascrip Essay 1

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.