为元素扩展新方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="box">
JQ方法
</div>
</body>
<script>
$.fn.extends({
colors:function(color){
this.css('background',color);
}
});
$('#box').colors('red');
</script>
</html>
为元素扩展新方法;
语法 $.fn.extend(obj)
obj:key 方法名,value 处理程序,实现的效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="box">
JQ方法
</div>
</body>
<script>
$.fn.extends({
colors:function(color){
this.css('background',color);
}
});
$('#box').colors('red');
$.extend({
min:function(a,b){
return a<b?a:b;
}
});
alert($.min(1,4))
</script>
</html>