[英]Jquery.Click() Doens't work after it's used one time
I have a really simple jquery.Click() function 我有一个非常简单的jquery.Click()函数
//hide divs
$("#a-1").hide();
$(".v-1").click(function(){
$("#a-1").show();
$(".v-1").addClass("c-it");
$(".c-it").click(function(){
$("#a-1").hide();
$(".v-1").removeClass("c-it");
});
});
So when v-1 is clicked a-1 has to show and it will add an class named c-it. 所以当点击v-1时,a-1必须显示,它将添加一个名为c-it的类。 That works after that i click c-it , a-1 will hide again and the c-it class will be removed.
在我点击c-it之后,a-1将再次隐藏并且c-it类将被删除。 So now we are the beginning again but now when i click v-1 nothing happens someone knows why?
所以现在我们又开始了,但现在当我点击v-1时,没有任何事情发生,有人知道为什么?
Html HTML
<i class="glyphicon glyphicon-plus v-1"> <span>This is a question</span></i>
<div id="a-1"><p>Awnser</p></div>
just use toggle() and toggleClass() better for you 更好地使用toggle()和toggleClass()
$("#a-1").hide();
$(".v-1").click(function() {
$("#a-1").toggle('hide');
$(".v-1").toggleClass("c-it");
});
You should use a single click handler that simply toggles the visible state and the class. 您应该使用单击处理程序,只需切换可见状态和类。
$(".v-1").click(function(){
$("#a-1").toggle();
$(".v-1").toggleClass("c-it");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.