博客
关于我
jquery的扩展方法介绍
阅读量:458 次
发布时间:2019-03-06

本文共 993 字,大约阅读时间需要 3 分钟。

    最近一直在写js,这其中也少不了一位js的主角了jQuery,下面介绍的是jQuery的一些扩展,也就是jQuery的扩展方法,jQuery的扩展方法有两种方式,一种是jQuery本身的扩展方法,另一种是jQuery所选对象的扩展方法,下面一起来看。

一、方式列表:

  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 制作整理,引用请写明出处谢谢合作,联系QQ:1370569】

转载地址:http://uqgfz.baihongyu.com/

你可能感兴趣的文章
MySQL中你必须知道的10件事,1.5万字!
查看>>
MySQL中使用IN()查询到底走不走索引?
查看>>
Mysql中使用存储过程插入decimal和时间数据递增的模拟数据
查看>>
MySql中关于geometry类型的数据_空的时候如何插入处理_需用null_空字符串插入会报错_Cannot get geometry object from dat---MySql工作笔记003
查看>>
mysql中出现Incorrect DECIMAL value: '0' for column '' at row -1错误解决方案
查看>>
mysql中出现Unit mysql.service could not be found 的解决方法
查看>>
mysql中出现update-alternatives: 错误: 候选项路径 /etc/mysql/mysql.cnf 不存在 dpkg: 处理软件包 mysql-server-8.0的解决方法(全)
查看>>
Mysql中各类锁的机制图文详细解析(全)
查看>>