JQUERY:图像替换问题

时间:2010-08-04 18:33:19

标签: jquery

我的“hideText”图片出现问题,取代了我的“showText” 谁知道为什么?如果show和hide都是文本,这可以正常工作, 但是当展示和隐藏是图像时根本不存在。

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

1 个答案:

答案 0 :(得分: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>
相关问题