jquery编写自己的插件

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>

你可能感兴趣的:(html,jquery)