zoukankan      html  css  js  c++  java
  • JQuery$.extend()用法

    1.合并多个对象。

    <span style="font-size:18px;">//用法: jQuery.extend(obj1,obj2,obj3,..)
    var Css1={size: "10px",style: "oblique"}
    var Css2={size: "12px",style: "oblique",weight: "bolder"}
    $.jQuery.extend(Css1,Css2)
    //结果:Css1的size属性被覆盖,而且继承了Css2的weight属性
    // Css1 = {size: "12px",style: "oblique",weight: "bolder"}
    </span> 
    

    2.深度嵌套对象。

    <span style="font-size:18px;"> jQuery.extend(
    { name: “John”, location: { city: “Boston” } },
    { last: “Resig”, location: { state: “MA” } }
    );
    // 结果:
    // => { name: “John”, last: “Resig”, location: { state: “MA” } }
    // 新的更深入的 .extend()
    jQuery.extend( true,
    { name: “John”, location: { city: “Boston” } },
    { last: “Resig”, location: { state: “MA” } }
    );
    // 结果
    // => { name: “John”, last: “Resig”,
    // location: { city: “Boston”, state: “MA” } }
    </span>
    

    3.可以给jQuery添加静态方法。

    <span style="font-size:18px;"><html>
    <head>
    <title></title>
    </head>
    <body>
    <script type="text/javascript" src="jquery.2.0.3.js"></script>
    <script type="text/javascript">
    $.extend({
    add:function(a,b){return a+b;},
    minus:function(a,b){return a-b},
    multiply:function(a,b){return a*b;},
    divide:function(a,b){return Math.floor(a/b);}
    });
    
    var sum = $.add(3,5)+$.minus(3,5)+$.multiply(3,5)+$.divide(5,7);
    console.log(sum);
    </script>
    </body>
    </html></span>
    
  • 相关阅读:
    WCF添加服务失败。服务元数据可能无法访问。请确保服务正在运行并且正在公开元数据。
    【C#】 实现WinForm中只能启动一个实例
    centos7防火墙问题
    ftp搭建记录
    centos7常用命令
    RocketMQ部署
    mongedb主从
    redis 主从复制+读写分离+哨兵
    keepalive+nginx
    分布架构分析
  • 原文地址:https://www.cnblogs.com/ly-lyq/p/9255127.html
Copyright © 2011-2022 走看看