JQuery插件的两种写法

第一种

js:

(function (jQuery){
this.show = function(title){
this.title=title;
};
this.show2 = function(){
alert(
this.title);
};
jQuery.messager
= this;
return jQuery;
})(jQuery);

html:
Code

 

第二种

js:

Code
$.fn.messager = function(options){
var defaults = {
title:
"this is a test!"
};
$.extend(defaults,options);
alert(defaults.title);
return this;
};

 

html:

Code
<script src="jquery.js"></script>
<script src="js.js"></script>
<script>
$(document).ready(
function(){
$(
"#d").messager().hide();
});
</script>
posted @ 2008-12-05 00:08  Jonve  阅读(3217)  评论(0)    收藏  举报