Learn JS Basics (1)

Source: Internet
Author: User

How to get elements in JS

To get an element by an ID name:
document.getElementById (' ID of element ')

Events: Mouse events, keyboard events, system events, form events, custom events ....
OnClick//Click events
onmouseover//mouse move in
onmouseout//Mouse away
ONMOUSEDWN//Press to show something later
OnMouseUp///mouse raised an event
OnMouseMove//Stroke events


How to add an event:
element. onmouseover
Function: Can be understood as-command, do something
Function name () {//Definitely not active!
Document get element by id ' link '
Docuemnt.getelementbyid (' link ');
}
1, Direct call: Name ();
2. Event invocation: element. event = function name Odiv.onclivk= name;

function () {} anonymous functions
element. event = function () {};

Test: Alert (1); A warning box with a OK button
Alert ('); String double quotes are also possible, as long as the pairing appears
Variable:
var li = document.getElementById (' lis ');
var num = 123;
var name = ' Leo ';

Learn JS Basics (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.