How to call two methods on button's onclick method in HTML or JavaScript ?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
Try this:
Or, call second function at the end of first function:
...and call func1() onclick of button:
As stated by Harry Joy, you can do it on the
onclick
attr like so:Or, in your JS like so:
Or, if you are assigning an onclick programmatically, and aren't sure if a previous onclick existed (and don't want to overwrite it):
If you need the functions run in scope of the element which was clicked, a simple use of apply could be made:
The modern event handling method:
The first argument is the event, the second is the function and the third specifies whether to allow event bubbling.
From QuirksMode:
Full details here: http://www.quirksmode.org/js/events_advanced.html
Using jQuery
if you're using jQuery, there is a nice API for event handling:
Full details here: http://api.jquery.com/category/events/
Hi,
You can also do as like below... In this way, your both functions should call and if both functions return true then it will return true else return false.
Thank you, Vishal Patel