【发布时间】:2013-10-27 20:44:04
【问题描述】:
我无法让这段代码工作:
$("a.expand_all").on("click",function(){
$(this).text('Hide');
$('.answer').each(function () {
$(this).slideDown(150, function () {
$(this).show();
});
});
}, function () {
$(this).text('Expand');
$('.answer').each(function () {
$(this).slideUp(150, function () {
$(this).hide();
});
});
});
我正在尝试折叠展开多个 div,但点击事件没有任何反应。我正在使用最新的 jQuery 1.10.1
【问题讨论】:
-
你有 dom 就绪处理程序吗?
$(document).ready(function(){ })围绕 jquery 代码? -
你的任何元素(如
a.expand_all)是由jQuery动态添加的吗? -
@EthanBrown 这有什么关系? OP 已正确使用委托。
-
我可能记错了,但它可能不起作用,因为您同时调用了点击事件的两半?
-
实际上,他们不是。 jsfiddle 演示:jsfiddle.net/Jammerwoch/sRnkw/1
标签: javascript jquery html toggle collapse