Jquery 扩展学习
来源:互联网 发布:指南数据库 编辑:程序博客网 时间:2024/05/18 11:13
@{ Layout = null;}<!DOCTYPE html><html><head> <meta name="viewport" content="width=device-width" /> <title>JqueryIndex</title> <script src="~/docs/js/jquery-2.1.3.min.js"></script> <script> // 创建一个闭包 (function ($) { // 插件的定义 $.fn.hilight = function (options) { debug(this); // build main options before element iteration var opts = $.extend({}, $.fn.hilight.defaults, options); // iterate and reformat each matched element return this.each(function () { $this = $(this); // build element specific options var o = $.meta ? $.extend({}, opts, $this.data()) : opts; // update element styles $this.css({ backgroundColor: o.background, color: o.foreground }); var markup = $this.html(); // call our format function markup = $.fn.hilight.format(markup); $this.html(markup); }); }; // 私有函数:debugging function debug($obj) { if (window.console && window.console.log) window.console.log('hilight selection count: ' + $obj.size()); }; // 定义暴露format函数 $.fn.hilight.format = function (txt) { return '<strong>' + txt + '</strong>'; }; // 插件的defaults $.fn.hilight.defaults = { foreground: 'red', background: 'yellow' }; // 闭包结束 })(jQuery); //(function($) { // $.fn.extend({ // hilight: function(options) { // //var defaults = { // // foreground: 'red', // // background: 'yellow' // //}; // var $this = $(this); // var opt = $.extend({},$.fn.hilight.defaults,options); // var o = $.extend($.mate?$.extend({},opt,$this.data):opt); // $this.css({ // backgroundColor: o.background, // color: o.foreground // }); // } // }); // $.fn.hilight.defaults = { // foreground: 'red', // background: 'yellow' // }; //})(jQuery); $(document).ready(function () { //$('#myDiv').hilight({ //}); $('.hilight').hilight(); }); </script></head><body> <div id="myDiv" class="hilight { background: 'red', foreground: 'white' }">myDiv</div><div> @*<ul id="ul"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul>*@</div> <div class="hilight { background: 'red', foreground: 'white' }"> Have a nice day! </div> <div class="hilight { foreground: 'orange' }"> Have a nice day! </div> <div class="hilight { background: 'green' }"> Have a nice day! </div> </body></html>
0 0
- Jquery 扩展学习
- 【学习笔记】jQuery库扩展
- 学习笔记-jQuery扩展示例
- jQuery源码学习笔记:扩展工具函数
- jQuery 学习第七课 扩展jQuery的功能 插件开发
- jQuery源码学习之六 (jQUery中扩展方法)
- jQuery源码学习之七 (jQuery中扩展方法)
- jQuery学习之用自定义插件来扩展jQuery
- JQuery 扩展
- jquery扩展
- jquery 扩展
- jquery 扩展
- Jquery 扩展
- jquery扩展
- jquery扩展
- Jquery扩展
- jquery扩展
- jQuery扩展
- poj 2104 K-th Number(划分树)
- PostgreSQL的日志类型
- failed to load OpenCL runtime
- poj Red and Black(dfs)
- Mysql 安装(centOS)
- Jquery 扩展学习
- JavaScript允许对任意数据类型做比较
- js判断客户端
- 硬件高速缓存&TLB
- web项目开发之DWZ
- 尊重他人的劳动
- 通俗理解LDA主题模型
- hdoj 1878 欧拉回路
- Asp.net 清除微信缓存的另类方法