Several functions of jquery that are more practical, but that many people ignore

Source: Internet
Author: User

People in contact with the work, these functions are less frequently used, I use a few more useful functions to share.

You have what you like, and you can share it.

1.filter 使用了我要什么就有什么

This function not only makes it easy to filter custom HTML, but also allows you to filter json and array

Filter the result of an array of 2

Array

JQuery ([2,3,3]). Filter (function (i,v) {return v==2})

Json

JQuery ([{id:2},{id:3},{id:4}]). Filter (function (i,v) {return v.id==2})

  

Html

$ ("P"). Filter (function (index) {  return $ (this). attr ("id") ==2;});

  

2, the params mother in also don't need but heart I spell URL

It is easy to spell a collection for MVC to receive and let the traditional url+ "? id=" +id+ "&name=" This code disappear

var myObject = {  A: {    one:1,     two:2,     three:3  },   B: [1,2,3]};var recursiveencoded = $.param (myOb ject) var recursivedecoded = decodeURIComponent ($.param (myObject)); alert (recursiveencoded); alert (recursivedecoded );//a%5bone%5d=1&a%5btwo%5d=2&a%5bthree%5d=3&b%5b%5d=1&b%5b%5d=2&b%5b%5d=3//a[one]=1&a [Two]=2&a[three]=3&b[]=1&b[]=2&b[]=3

  

3,closest mother in also don't need but heart I or to pocket money, Dad don't look for grandpa. Grandpa's not looking for Grandpa's dad, digging a grave without giving me

Closest first checks whether the current element matches, and if so, returns the element itself directly. If it does not match, look up the parent element, one layer at a level, until the element that matches the selector is found. If nothing is found, an empty jquery object is returned.

  

Several functions of jquery that are more practical, but that many people ignore

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.