我的代码正在工作,但需要点击两次来激活我的链接(一次用于点击事件,一次用于切换事件)。我该怎么做才能让它变成只有我必须点击一次,以便切换会自动发生?使用带切换事件的jQuery .live
//Show or Hide Comments
$('#showHideComments').live('click', function() {
$('#showHideComments').toggle(function() {
$(".commentsSwitch").animate({"marginLeft": "+=53px"}, 500);
$("#comments").fadeIn(300);
$("#addComment").fadeIn(300);
},function(){
$(".commentsSwitch").animate({"marginLeft": "-=53px"}, 500);
$("#comments").fadeOut(300);
$("#addComment").fadeOut(300);
});
});
谢谢!
Pssst,结合选择呢! – 2010-01-31 17:39:52
@尼克,很棒的一点。更新。谢谢! – 2010-01-31 17:43:17
谢谢!正是我需要的。我确实需要使用live,因为数据是通过我的php脚本通过ajax返回的。感谢您的优化,我仍然在学习:) – 2010-01-31 17:49:29