欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery判斷一個(gè)元素是否可見的方法

 更新時(shí)間:2015年06月05日 14:55:41   作者:三雨二草  
這篇文章主要介紹了jQuery判斷一個(gè)元素是否可見的方法,涉及jQuery鏈?zhǔn)讲僮骷皹邮脚卸ǖ募记?需要的朋友可以參考下

本文實(shí)例講述了jQuery判斷一個(gè)元素是否可見的方法。分享給大家供大家參考。具體如下:

jQuery 可以很容易地確定一個(gè)元素是可見的或是隱藏的,然后分別做不同的處理。如:我想根據(jù)某 div 是否可見,在按鈕上顯示不同的文字和圖標(biāo)??梢赃@樣實(shí)現(xiàn):

方法一:

$('#para_div button').click(function() {  
   if($(this).next().is(":visible")) {        
    //$(this).html('顯示');  
    $(this).css({"background":"url(/images/btn_arrow_down.png) no-repeat"});  
   }  
   else {  
    //$(this).html('隱藏');   
    $(this).css({"background":"url(/images/btn_arrow_up.png) no-repeat"});    
   }   
  $(this).next().slideToggle('fast');  
 });

方法二:

$('#para_div button').click(function() {  
   if($(this).next().css('display') == 'none') {        
    //$(this).html('隱藏');   
 $(this).css({"background":"url(/images/btn_arrow_up.png) no-repeat"});
   }  
   else{  
    //$(this).html('顯示');  
 $(this).css({"background":"url(/images/btn_arrow_down.png) no-repeat"});   
   }   
  $(this).next().slideToggle('fast');  
});

方法三:

$('#para_div button').click(function() {  
 var $cn = $(this).next();  
 //$(this).html(($cn.is(":visible")) ? '顯示' : '隱藏');  
(this).css(($cn.is(":visible")) ?  
{"background":"url(images/btn_arrow_down.png) no-repeat"} :  
{"background":"url(images/btn_arrow_up.png) no-repeat"});  
 $cn.toggle('fast');
});

希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論