//第一种 $(‘.class‘).css(‘display‘)==‘none‘ //第二种,注意加冒号,:visible $(‘.class‘).is(‘:visible‘)
$(‘.box p‘).click(function(){ //判断元素是否隐藏 //第一种 $(‘.txt‘).css(‘display‘)==‘none‘ //第二种 $(‘.txt‘).is(‘:visible‘) // if($(‘.txt‘).is(‘:visible‘)){ var display=$(‘.txt‘).css(‘display‘) if(display==‘none‘){ $(‘.txt‘).show() $(this).addClass(‘red‘) $(‘.txt‘).addClass(‘blue‘) /********************如果在js里面放样式的话,在关闭的时候,样式不会移除,所以不要在js里面加样式***********************************/ /* $(‘.red‘).css({ ‘color‘:‘red‘, ‘fontSize‘:‘20px‘ }) $(‘.blue‘).css({ ‘color‘:‘blue‘, ‘fontSize‘:‘10px‘ })*/ }else{ $(‘.txt‘).hide().removeClass(‘blue‘) $(this).removeClass(‘red‘) $(‘.txt‘).removeClass(‘blue‘) } })
原文:http://www.cnblogs.com/summerXll/p/6498862.html