2010-08-04 8 views
0

Avoir un problème avec mon image "hideText" remplaçant mon "showText" Quelqu'un sait pourquoi? Cela fonctionne bien si afficher et masquer sont à la fois du texte, mais pas du tout quand afficher et masquer sont des images.JQUERY: Image remplaçant des problèmes

$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>'; 

Répondre

0

Essayez ce script. vérifier les noms des images comme "panelup.gif"/"panelUp.gif" va utiliser 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>