1, the concept of the event:
JavaScript gives us the ability to create dynamic pages, and every element in the Web page can produce certain events that trigger JavaScript functions. We can think of an event as a behavior that can be detected by JavaScript.
2. Event Flow:
The event flow is mainly divided into bubble type event and capture type event. Internet Explorer currently supports only bubbling events, and browsers that support standard DOM, such as Firefox, Chrome, and so on, are supported.
3. Use the return value to change the default behavior of HTML elements:
Most HTML elements contain their own default behavior, such as hyperlinks, submit buttons, and so on. We can block its default behavior by adding "return false" to the binding event.
4, the Universal Event monitoring method:
(1) Binding HTML element attributes:
<input type= "button" value= "ClickMe" onclick= "Check (this)" >
(2) Binding DOM Object properties:
document.getElementById ("xxx"). Onclick=test;
<!DOCTYPE HTML><HTMLLang= "en"> <Head> <MetaCharSet= "Utf-8"> <title>JavaScript two universal ways to bind events</title> <Scripttype= "Text/javascript"> functiontest1 () {alert ("Binding HTML element Properties"); } functiontest2 () {alert ("binding DOM Object Properties"); } </Script> </Head> <Body> <ahref= "Https://www.baidu.com"onclick= "return false">Baidu</a> <!--hyperlinks have their own default behavior, which is to jump to the page when clicked. If you want to remove the default behavior, you can bind an onclick event, onclick= "return false". This will not jump to the page. - <inputtype= "button"ID= "Test1"value= "Test 1"onclick= "test1 ()"> <Buttontype= "button"ID= "Test2"><b>Test 2</b></Button> <Scripttype= "Text/javascript">document.getElementById ("test2"). onclick=test2;//parentheses are not allowed here, and parentheses indicate the calling function. /*Note: The function needs to be executed by a subsequent trigger, and the above sentence is not placed inside the function, and JavaScript is parsed from the top down to the code above,
If you have not resolved to the <body> Id--test2, you will get an error. So JavaScript code has to be put in the back. */ </Script> </Body></HTML>
JavaScript event concepts and monitoring events