欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery通過(guò)索引值操作html元素的代碼

 更新時(shí)間:2023年05月01日 12:12:58   作者:maidu_xbd  
這篇文章主要介紹了jquery通過(guò)索引值操作html元素的代碼,需要的朋友可以參考下

eq() :返回帶有被選元素的指定索引號(hào)的元素。注意:索引號(hào)從 0 開(kāi)頭,所以第一個(gè)元素的索引號(hào)是 0(不是 1)。

remove(): 移除被選元素,包括所有文本和子節(jié)點(diǎn)。

html():返回或設(shè)置被選元素的內(nèi)容。

attr():設(shè)置或返回被選元素的屬性值。如attr("class", "aaa time")

prepend():被選元素的開(kāi)頭(仍位于內(nèi)部)插入指定內(nèi)容。

animationend 事件:在 CSS 動(dòng)畫(huà)完成后觸發(fā)。

如何在jquery中使用eq()方法可以參考這篇文章 http://www.dbjr.com.cn/article/59465.htm

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .aaa {
            color: red;
            animation: mymove 4s
        }
 
        @keyframes mymove {
            25% {
                font-size: 30px;
                color: chartreuse
            }
 
            50% {
                color: blue
            }
        }
    </style>
</head>
 
<body>
    <div id="person">
        <div><span id="t1" class="time">小明</span></div>
        <div id="t2"><span class="time">小濤</span></div>
        <div><span class="time">小花</span></div>
        <div><span class="time">小剛</span></div>
        <div><span class="time">小狗</span></div>
        <div><span class="time">小毛</span></div>
    </div>
    <script src="jquery-1.7.1.min.js"></script>
    <script>
        // 1.移除頁(yè)面上class=time的索引值為2的元素
        $(".time").eq(2).remove()
        // 2.設(shè)置頁(yè)面上class=time的索引值為0的元素的內(nèi)容為9999
        $(".time").eq(0).html(9999)
        // 3.設(shè)置頁(yè)面上class=time的索引值為1的元素的class="aaa time"
        $(".time").eq(1).attr("class", "aaa time")
        // 4.隱藏頁(yè)面上class=time的索引值為4的元素
        $(".time").eq(4).hide()
        // 5.往id=person的標(biāo)簽中第一行插入html
        var name = "maidu"
        $("#person").prepend("<div><span class='time' id=" + name + ">" + name + "</span></div>")
        // 6.監(jiān)聽(tīng)動(dòng)畫(huà),當(dāng)動(dòng)畫(huà)結(jié)束后去掉class=aaa
        document.getElementsByClassName("time")[2].addEventListener('animationend', function (e) {
            this.classList.remove("aaa")
        })
 
    </script>
</body>
 
</html>

到此這篇關(guān)于jquery通過(guò)索引值操作html元素的代碼的文章就介紹到這了,更多相關(guān)js索引值操作html元素內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論