本文主要是介绍jQuery.extend( object ); 扩展jQuery对象本身,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title> jQuery.extend( object ); 扩展jQuery对象本身</title>
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<script>
// jQuery.extend( object ); 扩展jQuery对象本身
// 用法一:
jQuery.extend({min: function(a, b) { return a < b ? a : b; },max: function(a, b) { return a > b ? a : b; }
});
var num = jQuery.min(2,3); // => 2
console.log(num); // 2
var num = jQuery.max(4,5); // => 5
console.log(num); // 5// 用法二:
var num = 10;
var order = new Object();;
// var order = new Array();; // 也是可以的!
order['a'] = 'aaa';
order['b'] = 'bbb';
order['c'] = 'ccc';
console.log(order);
jQuery.extend( order,{c:num} );
console.log(order);
/*
对象:Object {a: "aaa", b: "bbb", c: "ccc"}Object {a: "aaa", b: "bbb", c: 10}
数组:[a: "aaa", b: "bbb", c: "ccc"][a: "aaa", b: "bbb", c: 10]
*/
</script>
</body>
</html>
这篇关于jQuery.extend( object ); 扩展jQuery对象本身的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!