jquery 数组添加事件

宋嘉禧
2023-12-01

 html

<ul class="widget w-friend-pages-added notification-list friend-requests">
    <li class="inline-items">
        <div class="author-thumb">
            <img src="img/avatar41-sm.jpg" alt="author">
        </div>
        <div class="notification-event">
            <a href="jobPosition.html" class="h6 notification-friend">php工程师</a>
             <span class="chat-message-item">软通动力有限公司</span>
         </div>
         <span class="notification-icon unStar" data-toggle="tooltip" data-placement="top" data-original-title="收藏">
            <svg class="olymp-star-icon" data-toggle="modal" data-target="#exampleModalCenter">
                    <use xlink:href="svg-icons/sprites/icons.svg#olymp-star-icon"></use>
            </svg>
        </span>
        <span class="notification-icon isStar" data-toggle="tooltip" data-placement="top" data-original-title="已收藏">
            <i class="fas fa-star" data-toggle="modal" data-target="#exampleModalCenter2">
            </i>
        </span>
    </li>
</ul>

js

        
        var u=$(".unStar");
        for(var i=0;i<u.length;i++) {
            u[i].onclick=function () {
                $(this).css('display','none');
                $(this).next().css('display','block');
            }
        }

        var c=$(".isStar");
        for(var q=0;q<c.length;q++) {
            c[q].onclick=function () {
                $(this).css('display','none');
                $(this).prev().css('display','block');
            }
        }

 

 类似资料: