编写jQuery插件

给jQuery对象绑定一个新方法是通过扩展 $.fn对象实现的。让我们来编写第一个扩展

$.fn.bg = function () {    // this已绑定为当前jQuery对象:    this.css('backgroundColor', '#cfcfcf').css('color', '#d85030');
   return this; }

 

<!-- HTML结构 -->
<div id="changeBg"> 啦啦啦啦啦</p>
</div>

 

<!-- js结构 -->

$('#changeBg').bg 

posted @ 2018-07-16 18:41  粉色年华  阅读(67)  评论(0编辑  收藏  举报