扩展jQuery库函数第一种方式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
</head>
<body>
<script>
jQuery.extend({
max:function(a,b){
return a>b?a:b;
},
min:function(a,b){
return a>b?b:a;
}
});
console.log("最大值:"+$.max(1,3));
console.log("最小值:"+$.min(1,3));
</script>
</body>
</html>
在浏览器的控制台中查看执行结果:
扩展jQuery库函数第二种方式:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.8.3.js" ></script>
</head>
<body>
<input type="checkbox" name="selectAll" />全选
<input type="checkbox" name="hobby" value="0" />足球
<input type="checkbox" name="hobby" value="1" />篮球
<input type="checkbox" name="hobby" value="2" />乒乓球
<script>
jQuery.fn.extend({
check:function(){
this.attr("checked","checked");
},
uncheck:function(){
this.removeAttr("checked");
}
});
$("[name='selectAll']").click(function(){
$("[type='checkbox']").check();
})
</script>
</body>
</html>
上述代码简单实现了全选功能: