单击时添加和删除类Jquery

时间:2016-03-30 10:25:49

标签: jquery addclass removeclass seconds

有没有办法在点击后添加一个类,然后在2或3秒后删除它? 提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个:

        <div style="position:absolute; top:0; left:0;background-color:#ffffff;height:30px;">
        <ul>

                    <li style="float:right;"><a href="abc.html">TEST 1</a></li>
                    <li style="float:right;"><a href="abc.html">TEST 2</a></li>
                    <li style="float:right;"><a href="Index.jsp">TEST 3</a></li>
                </ul>
        </div><br><br><br>



ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

li {
    float: left;
    font-size:20px;

}

li a {
    display: block;
    text-align: center;
    padding: 16px 16px;
    text-decoration: none;
}

li a:hover:not(.active) {
    background-color: #111;
}

$("#your_click_element_id").on('click', function() { $(this).addClass("class_name");//or $("#id_of_whatever_you_want) setTimeout(function() { $(this).removeClass('class_name'); }, 2000); }); 将等待2000毫秒,然后执行setTimout

.removeClass()
相关问题