A tentative study of JavaScript glamour (1)

Source: Internet
Author: User
Tags function definition

Transferred from: csdn--http://blog.csdn.net/cherry_vicent/article/details/42120149

1. What is JavaScript?

Depending on the user's actions, you can then modify some elements, attributes, and so on on the page.

(1) Html+css static page, JS to add dynamic effect to the page

(2) The principle of webpage effect

JavaScript is about modifying styles

(3) The process of writing JS:

"1" Layout: html+css

"2" property: determines which properties to modify

"3" event: Determine what actions the user is doing

"4" Write JS: In the event, with JS to modify the style of page elements

Fill: Event: User action, such as mouse click, move in, move out, etc.

(4) ID: in CSS, the ID as a selector in the CSS exists, and in JS it has a more extensive use,

in JS play the role of Tag (element) name, such as <div id= "Div1" >......</div>,id in this example played the role of Div name, Div1 is the name of Div

(5) div1.style.display= ' block '

Point. ------>, in general, belong to the relationship, is actually a property

equal sign =------> In mathematics, x=5, which means that the value of X is 5, that is equal.

In JS, the equals sign is not equal, the equals is assigned, what becomes, and the value to the right is assigned to the left.

2, the first JS compatibility issues: document.getElementById

(1) in the FF and the lower version of Chrome, is not directly with the ID to use, there is a compatibility problem

The true compatibility notation is document.getElementById(' ID name '), which is available under any browser

such as: document.getElementById (' Div1 ');

get the elements out by div1 this ID and then use the

Note: Remember that you cannot use the ID directly, but you have to get it through getElementById (take the element out) before you can use

(2) Web page skin Change

(1) Any label can be added with ID, including link

(2) Any property of any label can also be modified

(3) How to write in HTML, JS in how to write, only one exception is class, because class in JS is the key word (reserved word), so can not be directly used, to write classname

3. Introduction of functions: because it is messy to write code directly within an event

(1) function basic format:

[JavaScript]View PlainCopy
    1. Function name ()
    2. {
    3. Code
    4. }

the function in JS is somewhat similar to the class in CSS, and one of the biggest features of the class is that you write this style into class, and if you need this style, just take that class and use it.

Yes, the same function is also in JS.

(2) Definition and invocation of functions

[JavaScript]View PlainCopy
    1. function Show () //Definition
    2. {
    3. Alert (' abc ');
    4. }
    5. Show (); //Call

function definition: Just tell the system to have this function and not actually execute

Function call: Real execution of code in function

Note: the definition and invocation of a function is integral, only the definition is unresponsive, and only the call shows an error.

(3) The concept of introducing variables: considering reuse

Variable: It's an alias for something.

such as var Odiv=document.getelementbyid (' Div1 '), to the back of this large string took an individual named Odiv. Seeing Odiv is just as effective as seeing document.getElementById (' Div1 ').

Note: (1) If you want to manipulate an element, you must first select it, for example, now you want to manipulate the text element, then you need to add an ID, such as id= "Txt1", and then the function functions

getElementById to choose it.

(2) Who to operate, who to get

(3) A function is required, this function is prepared for the button, because it requires a function to click

4, if judgment: such as click the button to show/Hide div (popup menu)

(1) If the basic format of the judgment:

[JavaScript]View PlainCopy
    1. if (condition)
    2. {
    3. Statement 1
    4. }
    5. Else
    6. {
    7. Statement 2
    8. }


Translate: Execute statement 1 if condition is true, execute statement 2 if condition is not established

Note:(1) if: if

(2) Conditions: is in the meaning of judgment, is encountered in different situations to do different operations, encountered different problems to do different treatment

(2) Single and double-equal (= and = =)

= Assignment (change, become)

= = Judgment (judging whether the two sides are equal)

(3) Add JS to a link

<!--<a href= "Javascript:alert (' a ');" > Links </a> -

<a href= "javascript:;" > Links </a>

In general A does not add JS code, but the Empty JS reason: (1) in a Riga JS code is not good (2) empty JS code instead of add #, because it will not be like # to jump to the top of the page.

A tentative study of JavaScript glamour (1)

Related Article

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.