How does JQuery customize extension interfaces?

Source: Internet
Author: User

JQuery, as a lightweight JS framework, has its unique advantages. Many web programmers are happy. In addition to rich client processing and animation functions. It also provides custom extension interfaces for more people to develop extension JQuery. Use a simple example to demonstrate this interface. I think this is enough for many people to understand the path. The following example references JQuery APIs.

$.extend({     max: function(a, b) {         return a > b ? a : b;     },     min: function(a, b) {        return a > b ? b : a;     },     avg: function(a, b) {         return a / b;     }});

This example adds a new function to JQuery, which is a static function.
 
The call is as follows:

jQuery.min(2,3); // => 2jQuery.max(4,5); // => 5

It is also very easy to extend functions for components. For example, you want to extend the TextBox function so that it can be highlighted when the focus is obtained. If the focus is lost, the highlight is canceled. Of course, the highlighted effect can be implemented using CSS. Therefore, you can use a color name as a parameter. The Code is as follows:

$. Fn. hightlight = function (colorName) {this. mouseover (function () callback (this).css ('background-colorName); // this is a reference to the component itself}); this. mouseout (function () callback (this).css ('background-color ','');});}

The call is as follows:

$(function() {$('#test').hightlight('red');});
Articles you may be interested in
  • PHP obtains the week of the specified date, the first day of the month and the last day of the month.
  • Js address bar special effects (display the size of all images with links on the page and view the height of the current browser)
  • Php SDK for retrieving pm2.5 data from a certain place (pm2.5 php api)
  • How to Use constants defined by define in a program in a smarty Template
  • QQ floating Customer Service Code, very easy to expand
  • How to obtain the complete url address and parameters in javascript
  • CSS intercepts strings to automatically add ellipsis
  • Extension of the for loop in the smarty Template

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.