简体   繁体   中英

what does the "event.type " in the book mean?

I read the javascript for web developer and I find that words

 <input type="button" value="click me" onclick="alert(event.type)">

I don't understand why the books say it output "click" ;why the event.type point to that

The type property of an event object tells you the type of event it is.

It is a click event because it the event listener is a click event listener (assigned with the onclick attribute).

It might be more useful if you were using an event handler function that was shared among different types of events and you needed subtle differences between how they were handled.

This alerts the "event.type". The event type is "click" as in this alert only works when you "click" the button. See more examples here: https://javascript.info/introduction-browser-events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM