Jquery is a few useful functions that many people ignore.

Source: Internet
Author: User

Jquery is a few useful functions that many people ignore.

Among the people I work with, these functions are used less frequently. I will share some useful functions with you.

 

You can share with me what you like.

 

1,When the filter is used, everything I need

This function can not only easily filter custom HTML, but also filter JSON and ARRAY

 

Returns the result of filtering 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. params Mom doesn't need it either, but I want to pin the URL.

It is very convenient to spell a set for mvc to receive and make the traditional url + "? Id = "+ id +" & name = "This code disappears

var myObject = {  a: {    one: 1,     two: 2,     three: 3  },   b: [1,2,3]};var recursiveEncoded = $.param(myObject);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,Mom closest doesn't need it either, but I don't need pocket money. Dad doesn't want to ask grandpa ..Grandpa is not lookingGrandpa's father, dig graves if he doesn't give me one.

Closest first checks whether the current element matches. If yes, it returns the element itself. If there is no match, the parent element is searched up, and the parent element is located up one layer until the element matching the selector is found. If nothing is found, an empty jQuery object is returned.

  

 

 

 

 

Related Article

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.