jquery Plugin Development Demo

Source: Internet
Author: User

1(function ($) {2 $.fn.extend ({3"HighLight":function(options) {4             //checks whether the user passed in the parameter is legitimate5             if(!isValid (options))6                 return  This;7             varopts = $.extend ({}, defaluts, options);//overriding plug-in default parameters with Jquery.extend8             return  This. each (function() {//This is the jquery object. Return here to support chained calls9                 //iterate through all the DOM to be highlighted when calling the HighLight () plugin is a collection. Ten                 var$ This= $( This);//gets the current Dom's jquery object, where this is the DOM of the current loop One                 //set the DOM style according to the parameters A$ This. css ({ - BackgroundColor:opts.background, - Color:opts.foreground the                 }); -                 //formatting highlighted text -                 varMarkup = $ This. html (); -Markup =$.fn.highlight.format (markup); +$ This. HTML (markup); -             }); +  A         } at     }); -      -      -     //Default Parameters -     varDefaluts = { -Foreground: ' Red ', inBackground: ' Yellow ' -     }; to     //public formatting methods. The default is bold, and the user can override the method to achieve different formatting effects.  +$.fn.highlight.format =function(str) { -         return"<strong>" + str + "</strong>"; the     } *     //private methods to detect if the parameters are legitimate $     functionisValid (options) {Panax Notoginseng         return!options | | (Options &&typeofoptions = = = "Object")?true:false; -     } the}) (Window.jquery);

jquery Plugin Development Demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.