一个ng

编程入门 行业动态 更新时间:2024-10-25 00:23:56
一个ng-click按钮下有两个功能(Two functions under one ng-click button)

问题是我不想同时称他们为:

<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

更多推荐

本文发布于:2023-07-17 13:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1144999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!