Home > Article > Web Front-end > Learn the basics of JS
How to get elements in JS
Get elements by ID name:
document.getElementById('ID of element')
Events: mouse events, keyboard events, system events , form events, custom events....
onclick //click event
onmouseover //mouse moves in
onmouseout //mouse leaves
onmousedwn //something will appear after pressing it
onmouseup ///An event when the mouse is raised
onmousemove //Touch event
How to add an event:
Element.onmouseover
Function: can be understood as -Command, do something
function name(){ //It will definitely not be executed actively!
document get element by id 'link'
docuemnt.getElementById('link'); ......
}
1. Direct call: name();
2. Event call: element. event = function name oDiv.onclivk = name;
function (){} anonymous function
element. event = function (){};
Test: alert (1); Alert box with an OK button
alert(''); String double quotes are also acceptable, as long as they appear in pairs
Variables:
var li = document.getElementById('lis' );
var num = 123;
var name = 'leo';
The above is the detailed content of Learn the basics of JS. For more information, please follow other related articles on the PHP Chinese website!