JavaScript processing in jquery User Manual (5)

Source: Internet
Author: User

$. Browser () function. I hope it is not called incorrectly. The purpose is to determine the browser type and return the boolen value.

$ (Function (){
If ($. browser. MSIE)
{
Alert ("this is an Internet Explorer ");}
Else if ($. browser. Opera ){

Alert ("This Is An operabrowser ");}
})

When the page load determines the browser type, you can determine the types of MSIE, Mozilla, opera, and Safari browsers.

$. Each (OBJ,
FN)
OBJ is an object or array, and FN is a function executed in sequence on OBJ. Note that $ (). Each () is distinguished ()

$. Each ([0, 1, 2], function (I) {alert ("item
# "+ I +": "+ This );});

Input 0, 1, 2 as parameters to function (I) respectively.

$. Each ({name: "John", Lang: "JS"
}, Function (I) {alert ("name:" + I + ", value:" + this );

{
Name: "John", Lang: "JS"} is a hash object. Each group of hash objects is input to the function in sequence.

$. Extend (OBJ,
Prop)
Extend the first object with the second object

VaR settings = {validate: false, limit: 5,
Name: "foo "};
VaR Options = {validate: True, name: "bar"
};
$. Extend (settings, options );

After execution, the settings object is {validate:
True, limit: 5, name: "bar "}
You can use the following function to test

$ (Function (){
VaR settings = {
Validate: false, limit: 5, name: "foo "};
VaR Options = {validate:
True, name: "bar "};
$. Extend (settings, options );

$. Each (settings, function (I) {alert (I + "=" + this );
});
})

$. Grep (array, FN)
Use the FN function to filter the array. Pass the elements in the array to FN in sequence. The FN must return a boolen. If FN returns true, it will be filtered.

$ (Function (){
VaR arr = $. grep (
[0, 1, 2, 3], function (I) {return I> 2 ;});
$. Each (ARR,
Function (I) {alert (I );
});
})

We can see that the array [, 4] After $. grep is executed becomes [].

$. Merge (first,
Second)
Both parameters are arrays. The second array is the same as the first one, and then the two arrays are merged.

$ (Function (){
VaR arr = $. Merge (
[0, 1, 2], [2, 3, 4])
$. Each (ARR, function (I) {alert (I );
});
})

The result of ARR is [0, 1, 2, 3, 4].

$. Trim (STR)
Removes spaces at both ends of a string.

$. Trim ("Hello, how are you?
")

The result is "Hello, how are you? "

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.