【发布时间】:2011-05-24 21:38:02
【问题描述】:
当我点击隐藏信息链接时,它会显示显示信息,但它也会更改页面上所有其他框上的文本,当我点击隐藏信息它会切换 div class="revealBox" 上的 test 类,但它会在所有框上执行此操作,我想将其保留在相关框上。
我知道这将与 $(this) 有关,我只是不知道如何实现它。
这是我的 jquery
$(document).ready(function() {
// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='Hide Information';
var hideText='Show Information';
var is_visible = false;
$('.collapseLink').append('<span class="dottedBot">'+showText+'</span>');
$('.revealBoxContents').show();
$('a.collapseLink').click(function() {
// switch visibility
is_visible = !is_visible;
// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);
// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.revealBoxContents').slideToggle('slow');
// return false so any link destination is not followed
return false;
});
// toggle the bottom link
$('.collapseLink').click(function(){
$(this).parents('.revealBoxContents').stop(true, true).slideToggle('slow');
$(".collapseLink").html( (!is_visible) ? showText : hideText);
$(this).parent('.item').toggleClass('current');
});
$(".revealBoxTop a").click(function(){
$(this).toggleClass("closed").next().slideToggle("slow");
return false; //Prevent the browser jump to the link anchor
});
$('.revealBox a').click(function() {
$(".revealBox").toggleClass("test");
});
});
这是网址
【问题讨论】:
-
您可以使用
.is(':visible')测试可见性。 -
您使用
is_visible变量并更改其值。只需在if语句中使用上述属性$(this).is(':visible')。
标签: jquery