JavaScript event mechanism commonly used

js event mechanism:

Explanation: When we act action meets certain conditions, will trigger the execution of certain types of transactions.

Role: The main function is to combine js to use.
Contents:
1, single-double-click the event
  click: onclick time when the mouse click will trigger
 double-click: ondblclick when the mouse double-click time will be triggered

2, mouse events

  onmouseover when the mouse hovers over an HTML element when the trigger
  onmousemove when the trigger when the mouse moves over an HTML element
  onmouseout when the mouse out of an HTML element on the trigger

 

3, keyboard events  

  onkeyup when the keyboard on the bounce trigger an HTML element

  onkeydown When the keyboard in an HTML element upper and lower pressure trigger

4, the focus of the event

  onfocus When an HTML element gain focus trigger
  onblur when an HTML element lost focus trigger

5, page load event

  onload triggered when the page loaded successfully.
Note:
Add an event js in the first way:
using the HTML directly in event properties are added, the value of the attribute function monitor execution.
js events only valid on the current HTML element.
An HTML element can add a number of different events.
An event can trigger the sense performing multiple functions, but different functions you want to use semicolons

6, to the appropriate HTML tags to add an appropriate event

    onchange ---- select drop-down box
   onload ------ body tag
  HTML element simple double-click ------- users to click operation of
  mouse events ------ user can move a mouse operation.
  Keyboard events ------ user will be HTML elements keyboard operation.

7, when adding multiple events to HTML elements, pay attention to the conflict between events

  For chestnut: Click and double-click
  when the trigger event contains the same parts, will produce a conflict between events.

8, blocking event

  When the return value of the event is listening function returns to the event:
  the function will block the current event where HTML tags: false

Blocking event: 

function testA () { 
	Alert ( "blocking event"); 
	return to true; 
} 

<A the href = "http://www.baidu.com" target = "_ blank" the onclick = "return testA ( ) "> Baidu, </a>

9, hyperlinks call js function

  <a href="javascript:函数名()"> call js function </a>

Guess you like

Origin www.cnblogs.com/kilig/p/12184879.html