Home  >  Article  >  Web Front-end  >  Learn the basics of JS

Learn the basics of JS

巴扎黑
巴扎黑Original
2017-06-26 15:00:531125browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn