js插件实现代码
第一种实现写法
第二种实现写法
测试调用代码
第一种实现写法
;(function($){
$.fn.extend({
"liyh":function(value){
if(value==undefined){
alert("hello");
}else{
alert(""+value);
}
}
});
})(jQuery);
第二种实现写法
(function($){
$.fn.liyh=function(value){
if(value==undefined){
alert("hello");
}else{
alert(value);
}
};
})(jQuery);
测试调用代码
<html>
<head>
<script type="text/javascript" src="../jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
$(function(){
$(this).liyh("liyh");
});
</script>
</head>
<body>
</body>
</html>
本文详细介绍了JS插件的两种实现方式,并提供了测试调用代码,帮助开发者深入理解JS插件开发。

被折叠的 条评论
为什么被折叠?



