更新时间:2021-06-10 来源:黑马程序员 浏览量:
(1)考察目标
1)考察是否自己编写过拓展插件
2)是否知道为jQuery扩展插件的方法
(2)题目分析
1)通过$.extend()来扩展jQuery
2)通过$.fn 向jQuery添加新的方法
代码
// 1. 通过$.extend()来扩展jQuery // 语法: $.extend({}) // 缺点:这种方式无法利用jQuery强大的选择器带来的便利, $.extend({ log: function(msg) { var now = new Date(), y = now.getFullYear(), m = now.getMonth() + 1, d = now.getDate(), h = now.getHours(), min = now.getMinutes(), s = now.getSeconds(), time = y + '/' + m + '/' + d + ' ' + h + ':' + min + ':' + s; console.log(time + '--' + msg); } }) $.log('initializing'); //调用 // 2. 通过$.fn 向jQuery添加新的方法 /* 语法 $.fn.pluginName = function() { //your code goes here } */ // 常用的方式 $.fn.changeColor = function() { //在这里面,this指的是用jQuery选中的元素 this.css('color', 'red'); } $(function() { $('a').changeColor(); }) </script>(3)应用场景
【AI设计】北京143期毕业仅36天,全员拿下高薪offer!黑马AI设计连续6期100%高薪就业
2025-09-19【跨境电商运营】深圳跨境电商运营毕业22个工作日,就业率91%+,最高薪资达13500元
2025-09-19【AI运维】郑州运维1期就业班,毕业14个工作日,班级93%同学已拿到Offer, 一线均薪资 1W+
2025-09-19【AI鸿蒙开发】上海校区AI鸿蒙开发4期5期,距离毕业21天,就业率91%,平均薪资14046元
2025-09-19【AI大模型开发-Python】毕业33个工作日,就业率已达到94.55%,班均薪资20763元
2025-09-19【AI智能应用开发-Java】毕业5个工作日就业率98.18%,最高薪资 17.5k*13薪,全班平均薪资9244元
2025-09-19