简体   繁体   English

Javascript替换

[英]Javascript Replacement

Okay first of all i am really sorry about my last post but i really need help here i will put a clearer code about what i really want. 好吧,首先,我真的很抱歉我的上一篇文章,但是我在这里确实需要帮助,我将在代码中写上我真正想要的内容。 I am not good at javascript so hope you please help me. 我不擅长javascript,希望您能帮助我。

<span class="rating ipsType_smaller">
                <a href="" id="topic_rate_1" title="Rate topic 1 star">
                <i class="fa fa-star-o fa-lg rate_img"></i>
                </a>
                <a href="" id="topic_rate_2" title="Rate topic 2 stars">
                <i class="fa fa-star-o fa-lg rate_img"></i>
                </a>
                <a href="" id="topic_rate_3" title="Rate topic 3 stars">
                <i class="fa fa-star-o fa-lg rate_img"></i>
                </a>
                <a href="" id="topic_rate_4" title="Rate topic 4 stars">
                <i class="fa fa-star-o fa-lg rate_img"></i>
                </a>
                <a href="" id="topic_rate_5" title="Rate topic 5 stars">
                <i class="fa fa-star-o fa-lg rate_img"></i>
                </a>
</span>

okay here is html. 好的,这里是html。 IPB makes everything but i want to make a small edit with javascript. IPB可以完成所有工作,但是我想使用javascript进行一些小的编辑。 and no problem if it will change the html of css both are same so here is what i am thinking of: 没问题,如果它将更改css的html都是相同的,所以这就是我在想的:

When i hover on star 2, star 1 and star 2 will have same new class or the will change to something new when i hove on star 4, star 4 and all stars before star 4 will have new same class or the will change to same new thing 当我将鼠标悬停在星2上时,星1和星2将具有相同的新类,或者当我将星置于4上时,星4将变为新的类,或者星4之前的所有星将具有新的相同类或将变为相同的新类新事物

and when i click on star 4 or whatever star 2 a new class will be added to this class. 当我单击星级4或任何星级2时,新课程将添加到该课程中。

can this be done through javascript? 可以通过javascript完成吗?

Of course you can do it in JS, but also CSS only. 当然,您可以使用JS,也可以仅使用CSS。

Assuming you want to change background, 假设您要更改背景,

.rating:hover > a {
    background: red;         /* Set it for all elements */
}
.rating > a:hover ~ a {
    background: transparent; /* Unset it for following elements */
}

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM