Javascript Jquery:获取索引小于当前单击星号的星号
我有一个有星星的div: 然而,我需要使以前的明星充分以及。我尝试获取所有属性Javascript Jquery:获取索引小于当前单击星号的星号,javascript,jquery,Javascript,Jquery,我有一个有星星的div: 然而,我需要使以前的明星充分以及。我尝试获取所有属性index值小于$(this.attr(“index”)的星星,但没有成功 编辑: 使用prevAll的答案非常棒,但是如果有人能指出我在代码中做错了什么,我将不胜感激 要实现所需功能,只需使用prevAll()方法即可addBack()还可用于包含已单击的元素。试试这个: $('.review star')。在('click',function()上{ $(this).prevAll().addBack().te
index
值小于$(this.attr(“index”)
的星星,但没有成功
编辑:
使用
prevAll
的答案非常棒,但是如果有人能指出我在代码中做错了什么,我将不胜感激 要实现所需功能,只需使用prevAll()
方法即可addBack()
还可用于包含已单击的元素。试试这个:
$('.review star')。在('click',function()上{
$(this).prevAll().addBack().text(“★");
});
☆
☆
☆
☆
☆
要实现所需功能,只需使用prevAll()
方法。addBack()
也可用于包含已单击的元素。请尝试以下操作:
$('.review star')。在('click',function()上{
$(this).prevAll().addBack().text(“★");
});
☆
☆
☆
☆
☆
您可以尝试使用preval()
和nextAll()
$('.review star')。在('click',函数(){
/*desc=$(this.attr('data-desc');//获取描述
$('内容').text(desc)*/
//警惕(“是”);
//警报($(this.attr(“索引”));
$(此).text(“★")
//var stars=$(“.review star”).filter((索引,el)=>{
//返回parseInt($(el).attr(“index”)>$(this.attr(“index”);
//});
//控制台日志(星号);
//控制台.日志(星形.长度)
$(this).prevAll().text(“★");
$(this).nextAll().text(“☆");
});
☆
☆
☆
☆
☆
您可以尝试使用preval()
和nextAll()
$('.review star')。在('click',函数(){
/*desc=$(this.attr('data-desc');//获取描述
$('内容').text(desc)*/
//警惕(“是”);
//警报($(this.attr(“索引”));
$(此).text(“★")
//var stars=$(“.review star”).filter((索引,el)=>{
//返回parseInt($(el).attr(“index”)>$(this.attr(“index”);
//});
//控制台日志(星号);
//控制台.日志(星形.长度)
$(this).prevAll().text(“★");
$(this).nextAll().text(“☆");
});
☆
☆
☆
☆
☆
在jQuery的过滤器
中,此
与el
相同。在运行过滤器
之前,捕获此
的索引属性值。在jQuery的过滤器
中,此
与el
相同。在运行之前捕获此
的索引属性值g过滤器
.Wow!我还设法让它降低评级,如下所示:$(this).nextAll().addBack().text(“☆“”;
$(this.prevAll().addBack().text(“”)★);
非常感谢,这是一个纯粹的魔术!没问题,很高兴能帮上忙哇!我还设法让它降低了评级,就像这样:$(this.nextAll().addBack().text(“☆“”;
$(this.prevAll().addBack().text(“”)★);
非常感谢,这是纯粹的魔法!没问题,很乐意帮忙
<aside class="rate review-rate">
<span class="review-star" index="1">☆</span>
<span class="review-star" index="2">☆</span>
<span class="review-star" index="3">☆</span>
<span class="review-star" index="4">☆</span>
<span class="review-star" index="5">☆</span>
</aside>
$('.review-star').on('click', function () {
/* desc = $(this).attr('data-desc'); //get the description
$('#content').text(desc);*/
alert("yes");
alert($(this).attr("index"));
$(this).text("★")
var stars = $(".review-star").filter((index, el) => {
return parseInt($(el).attr("index")) > $(this).attr("index");
});
console.log(stars);
console.log(stars.length)
for (var starsKey in stars) {
//$(starsKey).text("★");
// console.log(starsKey);
}
});