0 0

jQuery缓存问题5

  最近在开发一个项目的时候遇到一个jQuery的缓存问题
  环境:
  一个邮件系统,当点击一个邮件时使用ajax打开,用JS改变邮件图标为已读。
 有一个功能,即是点击邮件图标时使图标变成选中状态:

    $j(document).ready(
        function(){
            $j(".mailSelecter").each(
                function(){
                    $j(this).toggle(
                        function(){
                            var src = $j(this).attr("src");
                            if(src=="/Content/images/mail_opened.gif")
                                $j(this).attr("src","/Content/images/mail_opened_selected.gif");
                            else
                                $j(this).attr("src","/Content/images/mail_new_selected.gif");
                        },
                        function(){
                            var src = $j(this).attr("src");
                            if(src=="/Content/images/mail_opened_selected.gif")
                                $j(this).attr("src","/Content/images/mail_opened.gif");
                            else
                                $j(this).attr("src","/Content/images/mail_new.gif");
                        }
                    );
                }
            );
        }
    );


会发现,如果查看未阅读的邮件时,用jQuery将图片变成已读的图标,但是在上面代码中,jQuery的缓存中,刚刚查看的那封邮件的图标还是未读的图标,所以,选中时,还是使用:
  $j(this).attr("src","/Content/images/mail_new_selected.gif");
期望:
  $j(this).attr("src","/Content/images/mail_opened_selected.gif");

2008年6月23日 10:34

1个答案 按时间排序 按投票排序

0 0

$j(document).ready(
  function(){
    $j(".mailSelecter").each(
      function(){
        $j(this).toggle(
          function(){
            var src = $j(this).attr("src");
            if(src=="/Content/images/mail_opened.gif")
              $j(this).attr("src","/Content/images/mail_opened_selected.gif");
            else
              $j(this).attr("src","/Content/images/mail_new_selected.gif");
          },
          function(){
            $j(this).attr("src","/Content/images/mail_opened.gif");
          }
        );
      }
    );
  }
);

2008年6月23日 13:14

相关推荐

Global site tag (gtag.js) - Google Analytics