Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

javascript - 从同一个onclick调用两个函数[重复](Call two functions from same onclick [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

HTML & JS

(HTML和JS)

How do I call 2 functions from one onclick event?

(如何从一个onclick事件中调用2个函数?)

Here's my code

(这是我的代码)

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

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

(这两个函数是pay()和cls()。)

Thanks!

(谢谢!)

  ask by user182 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add semi-colons ;

(添加分号;)

to the end of the function calls in order for them both to work.

(到函数调用结束,以便它们都能工作。)

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

I don't believe the last one is required but hey, might as well add it in for good measure.

(我不相信最后一个是必需的,但是嘿,不妨将它添加进去。)

Here is a good reference from SitePoint http://reference.sitepoint.com/html/event-attributes/onclick

(以下是SitePoint http://reference.sitepoint.com/html/event-attributes/onclick的一个很好的参考)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...