jQuery slideToggle调用一次 [英] jquery slideToggle call once
问题描述
那可能很简单,但是大约是凌晨2点,而且很困:)
That just could be very simple, but it's about 2AM and getting quite sleepy :)
我有一个简短的脚本,该脚本可以使"slideToggle" div不显示.
I have short script which "slideToggle" div from being non-displayed.
$('#cmnt_add').click(function () { $('.dark_div_add').slideToggle(1100); });
是否有机会进行一次锻炼,所以如果打开未显示的DIV,单击相同的链接将无济于事?
Is there a chance to make it workout once, so if non-displayed DIV is opened, clicking same link won't do a thing?
提前谢谢!
推荐答案
使用.one()
:
$('#cmnt_add').one("click", function () { $('.dark_div_add').slideToggle(1100); });
来自 jQuery的文档:
将处理程序附加到元素的事件.处理程序被执行 每个元素最多一次.
Attach a handler to an event for the elements. The handler is executed at most once per element.
此外,如果您知道它最初会被隐藏,那么使用.slideDown()
而不是.slideToggle()
可能是个好主意...
Also, if you know it'll be hidden initially, using .slideDown()
instead of .slideToggle()
may be a good idea...
这篇关于jQuery slideToggle调用一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!