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.