jquery Tools and Methods

Source: Internet
Author: User

jquery Methods and Tools

1. $.each (): Iterating through the data in an array or object

var obj = {

Name: ' Tom ',

Setname:function (name) {

THIS.name = Name

}

}

$.each (obj, function (key, value) {

Console.log (key, value)

})

2. $.trim (): Remove spaces on both sides of the string

3. $.type (obj): type of data obtained

Console.log ($.type ($))//' function '

4. $.isarray (obj): Determines whether an array

Console.log ($.isarray ($ (' body ')), $.isarray ([]))//False True

5. $.isfunction (obj): determining whether a function

Console.log ($.isfunction ($))//True

6. $.parsejson (JSON): Parse JSON string into JS object/array

var json = ' {' name ': ' Tom ', ' age ': ' + '//JSON object: {}

JSON object ===>js Object

Console.log ($.parsejson (JSON))

JSON = ' [{' name ': ' Tom ', ' age ': ' {'} ', ' ' name ': ' JACK ', ' age ': '-'} '//JSON array: []

JSON array ===>js array

Console.log ($.parsejson (JSON))

/*

Json.parse (jsonstring) JSON string--->js object/array

Json.stringify (Jsobj/jsarr) JS object/Array--->json string

7:

var $contents = $ ("#container >div")

var currentindex = 0//The currently displayed subscript

$ ("#tab >li"). Click (function () {

Hide the currently displayed div

$contents [currentindex].style.display= "None"

Displays the currently clicked element

Gets the index of the currently clicked element

var index=$ (this). Index ()

$contents [index].style.display= "Block"

Update the currently displayed subscript

Currentindex=index

})

8:

1. Manipulate any property

attr ()//For an operation with a property value other than Boolean

Removeattr ()

Prop ()//For an operation with a Boolean property value such as checked

2. Operation Class Properties

AddClass ()

Removeclass ()

3. Manipulating HTML code/text/values

HTML ()

Val ()

The practice code is as follows

1. Read the Title property of the first Div

Console.log ($ (' Div:first '). attr (' title '))//One

2. Set the Name property to all div (value = atguigu)

$ (' div '). attr (' name ', ' Atguigu ')

3. Remove the title property of all Div

$ (' div '). Removeattr (' title ')

4. Give all div settings class= ' guiguclass '

$ (' div '). attr (' class ', ' Guiguclass ')

5. Add class= ' abc ' to all Div.

$ (' div '). addclass (' abc ')

6. Remove the Guiguclass class for all Div

$ (' div '). Removeclass (' Guiguclass ')

7. Get the last Li tag body text

Console.log ($ (' li:last '). HTML ())

8. Set the first Li's label body as "

$ (' Li:first '). html ('

9. Get the value in the input box

Console.log ($ (': Text '). Val ())//Read

10. Set the value of the input box to Atguigu

$ (': Text '). Val (' Atguigu ')//Set read/write Unity

11. Click on the ' Select All ' button for full selection

attr (): Action property value is not a Boolean value property

Prop (): A property that specializes in manipulating property values to Boolean values

var $checkboxs = $ (': CheckBox ')

$ (' Button:first '). Click (function () {

$checkboxs. Prop (' checked ', true)

})

12. Click the ' Select All ' button to make all the selections

$ (' Button:last '). Click (function () {

$checkboxs. Prop (' checked ', false)

})

13 Setting CSS styles/reading CSS values

CSS () $ ("div"). CSS ()//read-write Oneness

$ ("P:eq (1)"). CSS ({

"Color": "#ff0011",

"Background": "Blue",

"width": 300,

"Height": 30

})

jquery Tools and Methods

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.