2010-08-04 67 views
0

我的「hideText」圖片替換我的「showText」 有問題任何人都知道爲什麼?如果顯示和隱藏都是文字, ,但是當顯示和隱藏都是圖像時,此功能正常工作。JQUERY:圖片替換問題

$payload .= '<script type="text/javascript"><!-- 
      $(document).ready(function() { 
       var showText="<img src=\'images/panelOpen.gif\' />"; 
       var hideText="<img src=\'images/panelup.gif\' />"; 
       $(".toggle").prev().append(\'<a href="#" class="toggleLink">\'+showText+\'</a> \'); 
       $(\'.toggle\').hide(); $(\'a.toggleLink\').click(function() { 
        if ($(this).html()==showText) { $(this).html(hideText); } 
        else { $(this).html(showText); } 

       $(this).parent().next(\'.toggle\').toggle(\'slow\'); 
        return false; }); }); 

        //--> 
      </script>'; 

回答

0

試試這個腳本。檢查圖像的名稱爲「panelup.gif」/「panelUp.gif」只是要使用Linux:

<script type="text/javascript"> 
<!-- 
    $(document).ready(function() { 

    var showText= '<img class="img-show" src="images/panelOpen.gif" />'; 
    var hideText= '<img class="img-hide" src="images/panelup.gif" />'; 

    $('.toggle').prev().append('<a href="#" class="toggleLink">'+showText+'</a>'); 
    $('.toggle').hide(); 

    $('a.toggleLink').bind('click', function(ev) { 

     ev.stopPropagation(); 

     if ($(this).find('img').hasClass('img-show')) { 
     $(this).empty().html(hideText); 
     } else { 
     $(this).empty().html(showText); 
     } 

     $(this).parent().next('.toggle').toggle('slow'); 

     return false; 
    }); 
    }); 

//--> 
</script>