jQuery插件封装(单个插件含多个分支函数)

网友投稿 550 2022-11-14

jQuery插件封装(单个插件含多个分支函数)

jQuery插件封装(单个插件含多个分支函数)

(function($) { var methods = { init: function(options) { var $settings = $.extend(true, { 'id': '' }, options); $(this).append("
函数 init,参数id:" + $settings.id); }, show: function() { $(this).append("
函数show,无参数"); }, hide: function() { $(this).append("
函数hide,无参数"); }, update: function(content) { $(this).append("
函数update,参数内容:" + content); } } $.fn.extend({ tooltip: function(method) { if(methods[method]) { methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if(typeof method == 'object' || !method) { methods.init.apply(this, arguments); } else { $(this).append('
Method [' + method + '] does not exist on jquery.tooltip'); } } });})(jQuery);$(document).ready(function() { $(".tooltip").tooltip(); $(".tooltip").tooltip({id: 1}); $(".tooltip").tooltip("show"); $(".tooltip").tooltip("hide"); $(".tooltip").tooltip("update", "这是新的内容工具提示!"); $(".tooltip").tooltip("alert");});

执行结果:函数 init,参数id:函数 init,参数id:1函数show,无参数函数hide,无参数函数update,参数内容:这是新的内容工具提示!Method [alert] does not exist on jquery.tooltip

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:JMeter连接Mysql数据库的实现步骤
下一篇:获取长效令牌 (API 云合同)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~