简体   繁体   English

这个多onChange事件是否有效

[英]Is this multi onChange event validate

I have multiple functions that need to fire on the onChange event will this work? 我有多个需要在onChange事件上触发的功能是否可以正常工作?

I cannot combine the functions. 我无法组合功能。

 onChange="avgFloatPipe(), ReserveFloatingPipe()" 

Thanks! 谢谢!

onChange="avgFloatPipe(); ReserveFloatingPipe();" if you insist on doing it inline and not making a third function that calls the other two. 如果您坚持要内联,而不要创建第三个函数来调用其他两个函数。

If you plan on doing things inline that syntax should be fine. 如果您打算内联处理,则语法应该没问题。 You could also terminate each function call with a semicolon. 您也可以使用分号终止每个函数调用。

http://codepen.io/anon/pen/JXevRy http://codepen.io/anon/pen/JXevRy

 function test1() { alert(1); } function test2() { alert(2); } 
 <input onchange="test1(), test2();" /><br /> or separating the statements<br /> <input onchange="test1(); test2();" /> 

You could also wrap the functions with a third function and call them both 您也可以将函数与第三个函数包装在一起,并同时调用它们

 function test1() { alert(1); } function test2() { alert(2); } function test3() { test1(); test2(); } 
 <input onchange="test3()" /> 

A third option is to bind the event using javascript. 第三种选择是使用javascript绑定事件。 One way to do this is by using an anonymous function. 一种实现方法是使用匿名函数。

 function test1() { alert(1); } function test2() { alert(2); } document.getElementById("example").onchange = (function () { test1(); test2(); }); 
 <input id="example" /> 

只需用半冒号分隔功能即可:

onChange="avgFloatPipe(); ReserveFloatingPipe()"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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