jquery Tutorial Examples and demo 4

Source: Internet
Author: User
Tags array object execution extend final hash key trim
css

test


CSS (name) gets the style named name
$ ("#a"). CSS ("color") will get the color value red in the style, ("#a"). CSS ("background") will get blue

CSS (prop) prop is a hash object that is used to set a large number of CSS styles
$ ("#b"). CSS ({color: "Red", Background: "Blue"});
The final effect is

test

,{color:" Red ", Background:" Blue "},hash object, Color is key," red "is value,

CSS (key, value) is used to set a separate CSS style
$ ("#b"). CSS ("Color", "red"); the final effect is

test



four: JavaScript processing

$.browser () to determine the browser type, return Boolen value

$ (function () {
if ($.browser.msie) {
Alert ("This is an IE browser");}
else if ($.browser.opera) {
Alert ("This is an opera browser");}
})

When the page is loaded to determine the type of browser, the types that can be judged are MSIE, Mozilla, Opera, Safari

$.each (obj, fn) obj is an object or array, and FN is the function that executes sequentially on OBJ, noting that the $ () is distinguished. each ()

$.each ([0,1,2], function (i) {alert ("Item #" + i + ":" + This);});

0,1,2 as a parameter and passed into function (i), respectively

$.each ({name: "John", Lang: "JS"}, function (i) {alert ("Name: + i +", Value: "+ this);

{Name: "John", Lang: "JS"} is a hash object, which in turn passes each set of objects in the hash to the function

$.extend (obj, prop) expands 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) filters the array by the function FN, passing the elements in the array to FN,FN must return a boolen, such as FN return true, will be filtered

$ (function () {
var arr= $.grep ([0,1,2,3,4], function (i) {return i > 2;});
$.each (arr, function (i) {alert (i);});
})

We can look at the execution $.grep after the array [0,1,2,3,4] becomes [0,1]

$.merge (first, second) two parameters are arrays, expel the second array with the same one, then combine two numbers and

$ (function () {
var arr = $.merge ([0,1,2], [2,3,4])
$.each (arr, function (i) {alert (i);});
})

You can see that the result of ARR is [0,1,2,3,4]

$.trim (str) remove spaces at both ends of the string
$.trim ("Hello, How are"?) "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.