zoukankan      html  css  js  c++  java
  • jquery 04

    $('div').slice(1,3).css('background','red').end().css('color','blue');  入栈原理图:

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <script src="jquery-2.0.3.js"></script>
    <script>
    
    
    $(function(){
        console.log( $('div'));//json对象Object { 0: <div>, 1: <div>, 2: <div>, 3: <div>, length: 4, prevObject: Object, context: HTMLDocument → new%202.html, selector: "div" }
        
        console.log( $('div').toArray() );//Array [ <div>, <div>, <div>, <div> ]
        
        $('div') : { 0 : div , 1 : div , 2 : div , length : 3 }
        
        $('div').toArray() : [div,div,div]
        
        $('div').get(-1).innerHTML = '222222222';
        
        for(var i=0;i<$('div').get().length;i++){
            $('div').get(i).innerHTML = '222222';
        }
        
        /*$('div').pushStack( $('span') ),pushStack()返回span,span的prevObject等于div,css('background','red')只会把span变红,
        end: function() {
            return this.prevObject || this.constructor(null);
        },
        调用end方法就是返回prevObject就实现了栈,多次调用end(),最后返回空,就不处理最后的css方法。*/
        
        $('div').pushStack( $('span') ).css('background','red').end().end().end().css('background','yellow');
        
    /* slice: function() { return this.pushStack( core_slice.apply( this, arguments ) ); }, core_slice = core_deletedIds.slice, core_deletedIds = [], $('div').slice(1,3)返回2.3两个div,他的prevObject = $('div')(4个div),css('background','red')就是把2个div变红,end().css('color','blue')把4个div变蓝。*/ $('div').slice(1,3).css('background','red').end().css('color','blue');

    /* eq: function( i ) { var len = this.length, j = +i + ( i < 0 ? len : 0 ); return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] ); }, */ $('div').eq(0).css('background','red'); var arr = ['a','b','c'] arr = $.map(arr,function(elem,i){ return elem + i; }); alert( arr );//[a0,b1,c2] }); </script> </head> <body> <div>div</div> <div>div</div> <div>div</div> <div>div</div> <span>span</span> </body> </html>
  • 相关阅读:
    关于下下载typora的相关说明
    Vue项目vscode 安装eslint插件的方法(代码自动修复)
    [0].Net开发者社区--您好大的官威啊!
    关于hadoop安装后无法访问web界面查看查看 NameNode 和 Datanode 信息
    C#(winform)记录阻止关闭页面方法
    Android开发:记录Cannot resolve symbol'R'问题解决记录
    C#Winform开发杂项记录
    C#Winform 使用NPOI导入、导出Excel
    C#记录一些用到的比对方法
    C#(Winform开发)Excel导出
  • 原文地址:https://www.cnblogs.com/yaowen/p/6906690.html
Copyright © 2011-2022 走看看