问题描述
在此中
<$ p $($ {code} $('#user_button')。switch(function(){
$(。hello)。addClass(active);
} ){
$(。hello)。removeClass(active);
});
使用jQuery .toggle
回调函数添加和删除类到一个元素。现在根据jQuery .toggle
, .toggle
最初用于在所选元素的可见性状态之间切换。
我做了一个jsfiddle演示:
在我的示例中,它似乎只是在回调函数之间交替,和可见性 #user_button
本身未被切换。我在文档中缺少什么?可以切换用于仅在功能之间交替使用
谢谢!
有两种切换方式... 和一个。他们应该以不同的方式命名他们,以避免这种混乱。
In this stackoverflow answer
$('#user_button').toggle(function () {
$(".hello").addClass("active");
}, function () {
$(".hello").removeClass("active");
});
The jQuery .toggle
callback function is used to add and remove classes to an element. Now according to the jQuery .toggle
documentation, .toggle
is originally used to switch between visibility states of the selected element.
I've made a jsfiddle demo: http://jsfiddle.net/taheri/nYdng/
In my example here it seems to only alternate between call back functions, and the visibility of the #user_button
itself is not being toggled. What am i missing out in the documentation here? Can toggle be used to only alternate between functions?
Thank you!
There are two toggle methods... this one and this one. They should have named them differently to avoid this confusion.
这篇关于正确使用jQuery切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!