美文网首页
3.VQuery获取和查找

3.VQuery获取和查找

作者: 大捕猎店 | 来源:发表于2017-10-11 21:47 被阅读0次

    eq方法

    VQuery.prototype.eq = function(n) {
        return $(this.elements[n]);
    };
    

    如果只返回this.elements[n],只是一个div,不能实现.eq(1).css('background-color',"red");这样的效果,所以包一层$(...);

    <style type="text/css">
    div{width: 100px; height: 100px; background-color: blue; border-style:solid;margin: 10px;}
    </style>
    <script src="vquery.js"></script>
    <script>
    $(function(){
        $('div').eq(1).css('background-color',"red");
    });
    </script>
    </head>
    <body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    </body>
    
    效果

    find方法

    index方法

    相关文章

      网友评论

          本文标题:3.VQuery获取和查找

          本文链接:https://www.haomeiwen.com/subject/xysgyxtx.html