本文介绍了如何使用jquery模拟mouseover事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样定义的星级评分系统:
I have a star rating system as defined like this:
<span class="rating_container">
<span class="star_container">
<a rel="nofollow" href="" class="star star_1" >1<span class="rating">Terrible</span></a>
<a rel="nofollow" href="" class="star star_2" >2<span class="rating">Bad</span></a>
<a rel="nofollow" href="" class="star star_3" >3<span class="rating">Bad</span></a>
<a rel="nofollow" href="" class="star star_4" >4<span class="rating">OK</span></a>
<a rel="nofollow" href="" class="star star_5" >5<span class="rating">OK</span></a>
<a rel="nofollow" href="" class="star star_6" >6<span class="rating">OK</span></a>
<a rel="nofollow" href="" class="star star_7" >7<span class="rating">Good</span></a>
<a rel="nofollow" href="" class="star star_8" >8<span class="rating">Good</span></a>
<a rel="nofollow" href="" class="star star_9" >9<span class="rating">Excellent</span></a>
<a rel="nofollow" href="" class="star star_10" >10<span class="rating">Excellent</span></a>
</span>
</span>
当鼠标悬停时,每个单独的星星都会着色.如何使用jquery模拟这一点?例如,我想将鼠标悬停在星5上.这是我尝试过的操作:
Each individual star is colored when a mouseover happens. How can I simulate this with jquery? For instance I'd like to mouseover star 5. This is what I've tried:
$('.star.star_5').addClass('active');
我想念什么?
推荐答案
尝试:
$(".star_5").trigger('mouseover');
这将触发鼠标悬停操作,无论它发生在什么地方,而不是模拟它,从而提供了一种针对将来的措施,以防止更改鼠标悬停处理程序.
This will trigger the mouseover action whatever it happens to be, rather than emulating it, offering a measure of future-proofing against changes to the mouseover handler.
这篇关于如何使用jquery模拟mouseover事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!