问题是我不想同时称他们为:
<button ng-click="startCounter(); stopCounter()" >
有没有办法实现这个? 这是我的代码,它使用两个按钮。
这是我的小提琴: https : //jsfiddle.net/v3vk3ho0/
The thing is i don't want to call them both at the same time like using:
<button ng-click="startCounter(); stopCounter()" >
Is there a way to implement this? Here is my code which is using two buttons.
Here is my Fiddle: https://jsfiddle.net/v3vk3ho0/
最满意答案
虽然你的问题不是很清楚,但由于你没有描述你真正想要或期望发生的事情,我想你想要改变点击点击的电话。 所以你想先点击按钮,然后是第二个,然后是第一个,再调用第一个函数,等等,所以这里是一个解决方案:
<button ng-click="_counterMode = !_counterMode; _counterMode ? startCounter() : stopCounter()" >这样做是在每次单击切换辅助变量_counterMode(从false到true,从true到false等)并根据其值执行函数1或函数2
although your question is not quite clear, since you do not describe what you actually want or expect to happen, i guess you want to alter the calls from click to click. so you want to call the first function when you click the button first, then the second, then the first again, etc. so here is a solution for that:
<button ng-click="_counterMode = !_counterMode; _counterMode ? startCounter() : stopCounter()" >what this does is on every click toggling the helper variable _counterMode (from false to true, from true to false, etc) and depending on its value execute function 1 or function 2
更多推荐
发布评论