zl程序教程

您现在的位置是:首页 >  前端

当前栏目

Jquery的扩展方法总结

2023-06-13 09:14:30 时间
一、方式列表:
  1.jQuery.extend(Object);   //jQuery本身的扩展方法
  2.jQuery.fn.extent(Object); //jQuery所选对象扩展方法
二、调用示例:
  1.jQuery本身的扩展方法实例如下:
复制代码代码如下:

jQuery.extend({
Meg:function(message){
alert(message);
},
MegToo:function(messageToo){
alert(messageToo);
}
});

  页面调用:jQuery.Meg("Hi,Stone");
  其中Meg和MegToo为我的jQuery自定义扩展方法,多个扩展方法之间用英文逗号隔开。
  2.jQuery所选对象扩展方法有两种书写方式。
  a)jQuery所选对象扩展方法实例一如下:
复制代码代码如下:

jQuery.fn.extend({
ShowHtml:function(showhtml){
jQuery(this).html(showhtml);
}
});

  页面调用:jQuery("#htmlDiv").ShowHtml("Stone,Hi!");
  其中ShowHtml为我的jQuery所选对象的扩展方法,多个扩展方法之间用英文逗号隔开。
  b)jQuery所选对象扩展方法实例二代码如下:
复制代码代码如下:
(function(jq){
jq.fn.ShowHtmlToo=function(showhtml){
jQuery(this).html(showhtml);
};
})(jQuery)

  调用相同与方式一:jQuery("#htmlDiv").ShowHtmlToo("Stone,Hi!");
【Stone制作整理】