我有一个最初隐藏的评论部分,将通过评论计数链接和/或添加评论的链接显示。
我希望通过任一链接打开评论部分,但如果它已经打开则不关闭。
$( "#commentsToggle").click(function() {
$( "#comments" ).toggle( "fast" );
return false;
});
$( ".comment-add a").click(function() {
$( "#comments" ).toggle( "fast" );
return false;
});
查看 jsfiddle http://jsfiddle.net/pQ2np/
谢谢
编辑:如果打开评论,“#commentsToggle”应该能够切换(隐藏)评论,“.comment-add a”应该只显示,而不是隐藏,因为它打开了 ajax 评论形式。
这是解决我需求的代码:
$( "#commentsToggle").click(function() {
$( "#comments" ).toggle( "fast" );
return false;
});
$( ".comment-add a").click(function() {
$( "#comments" ).show( "fast" );
return false;
});
最佳答案
如果您希望它们保持打开状态。使用 show()
而不是 toggle()
。
$( "#commentsToggle").click(function() {
$( "#comments" ).show( "fast" );
return false;
});
$( ".comment-add a").click(function() {
$( "#comments" ).show( "fast" );
return false;
});
关于javascript - 如果未切换,则通过两次单击切换一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24170291/