Call two functions from same onclick [duplicate]

2019-01-21 00:42发布

This question already has an answer here:

HTML & JS

How do I call 2 functions from one onclick event? Here's my code

 <input id ="btn" type="button" value="click" onclick="pay() cls()"/>

the two functions being pay() and cls(). Thanks!

9条回答
闹够了就滚
2楼-- · 2019-01-21 01:25

Just to offer some variety, the comma operator can be used too but some might say "noooooo!", but it works:

<input type="button" onclick="one(), two(), three(), four()"/>

http://jsbin.com/oqizir/1/edit

查看更多
时光不老,我们不散
3楼-- · 2019-01-21 01:31

Try this

<input id ="btn" type="button" value="click" onclick="pay();cls()"/>
查看更多
男人必须洒脱
4楼-- · 2019-01-21 01:32
onclick="pay(); cls();"

however, if you're using a return statement in "pay" function the execution will stop and "cls" won't execute,

a workaround to this:

onclick="var temp = function1();function2(); return temp;"
查看更多
登录 后发表回答