这是我的例子
<a href="javascript:void(0)" id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_A" title="10" style="text-decoration:none"><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_1" class="ratingStar emptyRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_2" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_3" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_4" class="ratingStar filledRatingStar" style="float:left;"> </span><span id="ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_Star_5" class="ratingStar filledRatingStar" style="float:left;"> </span>
</a>
所以我需要从锚标签的所有子元素点击中删除ratingStar filledRatingStar类并应用不同的类评级star emptyRatingStar
答案 0 :(得分:2)
您可以使用.addClass()
和.removeClass()
:
$(document).ready(function(){
$("#ctl00_ctl00_cphContent_cphInnerContent_ViewPhotosCtrl_ddRating_A").click(function(){
$(this).find("span").removeClass("filledRatingStar").addClass("emptyRatingStar");
});
});
希望这会有所帮助。干杯
答案 1 :(得分:1)
尝试:
$("a").click(function() {
$(this).children().removeClass("filledRatingStar").addClass("emptyRatingStar");
});
答案 2 :(得分:0)
$("a").click(function(){
$(this).children().removeClass("filledRatingStar").addClass("emptyRatingStar");
});