当前位置: 代码迷 >> Web前端 >> jquery编撰自己的插件
  详细解决方案

jquery编撰自己的插件

热度:39   发布时间:2012-10-07 17:28:51.0
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>
  相关解决方案