<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery扩展函数</title>
<script src="jquery.js"></script>
<script>
//$.extend({}) 是扩展jQuery这个类,为jQuery添加新的方法
//写法一
;(function($){
$.extend({
zhao:function(){
alert("这是我的第一个扩展函数");
},
lu:function(){
alert("这是我的第二个扩展函数");
}
})
})(jQuery);
//写法二
$(function(){
$.extend({
study:function(){
alert("study hard!")
}
})
})
//$.fn.extend({});解释:jQuery.fn=jQuery.prototype={};,所以jQuery.fn.extend扩展的是jQuery原型(对象)的方法,对象就是类的实例化。用法:$("selector").mm();mm()就是扩展的jQuery对象方法
;(function($){
$.fn.extend({
PHP:function(){
alert("PHP和JAVASCRIPT值得学习");
}
})
})(jQuery);
</script>
</head>
<body>
<div class="study">
<p>php,javacript,html5,css3,ajax,node.js,angular.js</p>
</div>
<script>
$(document).ready(function(){
$.zhao();
$.lu();
$.study();
$(".study").click(function(){
$(this).PHP();
})
})
</script>
</body>
</html>
jQuery扩展函数方法
最新推荐文章于 2021-04-09 00:04:50 发布