问题描述
我有一系列按钮.我们称它们为A,B,C.我将toggle方法附加到了这些按钮上.当我单击A时,将显示带有一些信息的div.如果我再次单击A,则该div将被删除.当我单击B时,与A相关的div被删除[如果仍处于打开状态],并显示与B相关的新div.这只是我们在许多网站上看到的基本切换.
I have a series of buttons. Lets call them A, B, C. I attached the toggle method to these buttons. When I click A, a div with some info will be shown. If i click A again, this div will will be removed. When i click B, the div related to A is removed[if still open] and a new div related to B is shown. It's just a basic toggle we see in many websites.
但是,当我单击A,然后依次单击B和A时,A将进行2次单击以显示其div.那是因为切换中的第二个功能仍在队列中而被触发.
However, when i click A, then B and then A again, the A will take 2 clicks to show its div. Thats because the second function in the toggle is triggered as it is still in queue.
查看此代码.我只是在这里更改按钮的文本以进行演示.
Look at this code. I am just changing text of the button here for demo.
如何防止它获得2次点击?
How to prevent it from taking 2 clicks?
推荐答案
您需要将click事件绑定到按钮,并相应地更改tet,而不要使用切换.我会用.each()
You need to bind a click event to the buttons and change the tet accordingly instead of using toggle. I would use .each()
这篇关于切换功能需要2次点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!