Home > Backend Development > PHP Tutorial > php-Please give me some advice! ~Achieve multiple identical elements. After clicking one of the elements to select, the other elements will not be selected by clicking again? ?

php-Please give me some advice! ~Achieve multiple identical elements. After clicking one of the elements to select, the other elements will not be selected by clicking again? ?

WBOY
Release: 2023-03-02 22:14:01
Original
1032 people have browsed it

phpjavascriptwebjqueryhtml5

There are 4 reviews. When you click on one review and add the category on, the others will not be clicked and will only prompt you that you have reviewed it~ I have been working on it for a long time~ Please give me some guidance (my current approach will be given to everyone liAdd on! So annoying)
php-Please give me some advice! ~Achieve multiple identical elements. After clicking one of the elements to select, the other elements will not be selected by clicking again? ?

Reply content:

Have you ever thought about what would happen if you clicked wrongly? . Which one should you click to add on, and then remove the on style of other li at the same time? If you are sure you want to click, it will not be modified. You must first determine whether there is an on item in the li, and if you click on something that does not already exist, it will prompt

<code> <style>li.on{color:green}</style>
<ul id="ul">
    <li>很满意</li>
    <li>满意</li>
    <li>一般</li>
    <li>差</li>
</ul>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script>
    $('#ul li').click(function () {
        if (!$(this).hasClass('on') && $(this).siblings().hasClass('on')) alert('你已经评价');
        else this.className='on'
    });
</script>

</code>
Copy after login

Single choice. Just make a single choice.

Yes, as mentioned on the first floor, you can dynamically add a class, and then click on it to have this class, but not others, you can judge it

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template