如果已使用jQuery访问链接图像,则更改其类别

如果已使用jQuery访问链接图像,则更改其类别,jquery,image,class,rollover,visited,Jquery,Image,Class,Rollover,Visited,我有一系列使用jQuery链接的滚动图像。单击链接后,我希望滚动图像将其类从“滚动”更改为“滚动2”,以便获得不同的图像集。以下是滚动图像的jQuery: $(document).ready(function() { $("img.rollover").hover( function() { this.src = this.src.replace("_off", "_on"); }, function() { this.src = this.src.replace("_on", "_off

我有一系列使用jQuery链接的滚动图像。单击链接后,我希望滚动图像将其类从“滚动”更改为“滚动2”,以便获得不同的图像集。以下是滚动图像的jQuery:

$(document).ready(function() {
$("img.rollover").hover( 
function() { this.src = this.src.replace("_off", "_on"); 
}, 
function() { this.src = this.src.replace("_on", "_off"); 
});
$("img.rollover2").hover( 
function() { this.src = this.src.replace("_off2", "_on2"); 
}, 
function() { this.src = this.src.replace("_on2", "_off2"); 
});
});
以下是链接图像的代码:

<a href="Mod1/index.html" target="_blank">
<img src="images/watch_off.png" class="rollover" />
</a>

最初的滚动效果很好,但我尝试使用来自的访问链接插件来触发将任何链接图像的类名更改为“滚动2”:

<script src="js/jquery.visited.js"  type="text/javascript"></script>
<script type="text/javascript">
$('#links a').visited(function () {
  // hides the li element
  $(this).img.removeClass("rollover");
  $(this).img.addClass("rollover2");
});
</script>

$('#链接a')。已访问(函数(){
//隐藏li元素
$(this.img.removeClass(“滚动”);
$(this.img.addClass(“滚动2”);
});
这似乎不起作用。你们中有谁能帮我解决这个问题吗?

你们可以使用这个方法,试试这个:

$('#links a').visited(function () {
  $(this).find('img').removeClass("rollover");
  $(this).find('img').addClass("rollover2");
});
这应该行得通

$(this).find('img').removeClass("rollover");
$(this).find('img').addClass("rollover2");
或者更好

 $(this).find('img').removeClass("rollover").addClass('rollover2');

运气不好。我想知道是否有比使用jQuery访问插件更好的方法来更改访问链接的类别。我注意到插件的演示似乎对我都不起作用。为什么不使用css
:visited
选择器?我该怎么做?我不能在css中添加条件句,对吗?