亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home Web Front-end JS Tutorial jQuery study notes change jQuery object_jquery

jQuery study notes change jQuery object_jquery

May 16, 2016 pm 05:49 PM
Change

jQuery代碼的任務(wù)就是生成jQuery對象A,操作jQuery對象A;生成jQuery對象B,操作jQuery對象B……但是若此過程中,對象A、B……之間有某種關(guān)系,那么完全沒必要一個個去$(selector),這很繁瑣的。因此jQuery提供了一些方法,使流程變?yōu)樯蒵Query對象A,操作jQuery對象A;更改為jQuery對象B,操作jQuery對象B……

  一個jQuery對象,既要進行N次操作,又要進行M次更改。因此有必要將生成的jQuery對象存儲在一個變量中,多次調(diào)用。然而,試想每進行一次操作和更改就得聲明一個新變量,這也很繁瑣啊。所以jQuery采取了鏈式操作的方法,即執(zhí)行操作后返回操作對象本身,于是可以持續(xù)執(zhí)行下一個操作,直到需要更改對象時方執(zhí)行更改,然后返回更改后對象。這實際上就是一種函數(shù)式思維。

  舉個例子,左右對比一下:

一般調(diào)用

鏈式調(diào)用

a=$(“div”);

a.addClass(“class”);

b=a.children(“ul”);

b.show();?????????????????????????

c=a.siblings();

c.removeClass(“class”);

$(“div”).addClass(“class”)

.children(“ul”).show().end()

.siblings().removeClass(“class”);

  接下來就介紹一下更改jQuery對象的各種方法:

更改為后代元素集合

方法

描述

等價

children(selector)

在原先元素的后代元素中,選取匹配selector的元素。若不設(shè)置參數(shù),children()等價于children(*),選取原先元素的所有子元素

$(selector1).children(selector2)≡$(selector1>selector2)

find(selector)

在原先元素的后代元素中,選取匹配selector的元素。若不設(shè)置參數(shù),find()等價于find(“:not(*)”),不會選取原先元素的任何后代元素

$(selector1).find(selector2)≈$(selector1 selector2)。若參數(shù)使用基本過濾選擇器,不是在全部后代元素中選取過濾匹配元素,而是在每一個后代元素中分別選取過濾匹配元素

contents()

選取原先元素的子元素或文本塊

?

更改為祖先元素集合

方法

描述

parent(selector)

在原先元素的父元素中,選取匹配selector的元素。若不設(shè)置參數(shù),parent()等價于parent(“*”),選取原先元素的所有父元素

parents(selector)

在原先元素的祖先元素中,選取匹配selector的元素。若不設(shè)置參數(shù),parents()等價于parents(“*”),選取原先元素的所有祖先元素

parentsUntil(selector)

選取原先元素的祖先元素,直到遇到匹配selector的元素為止,且不包括該元素。若不設(shè)置參數(shù),parentsUntil()等價于parents(),選取原先元素的所有祖先元素

offsetParents()

選取原先元素的最近祖先定位元素,且該元素CSS屬性display不能為none。定位元素指CSS屬性position

closest(selector)

在原先元素及其祖先元素中,選取匹配selector的最近元素

?

更改為兄弟元素集合

方法?????????????

描述

等價

next(selector)

在原先元素后面的第一個兄弟元素中,選取匹配selector的元素。若不設(shè)置參數(shù),next()等價于next(“*”),選取原先元素后面的第一個兄弟元素

$(selector1).next(selector2)≡$(selector1+selector2)

prev(selector)

在原先元素前面的第一個兄弟元素中,選取匹配selector的元素。若不設(shè)置參數(shù),prev()等價于prev(“*”),選取原先元素前面的第一個兄弟元素

nextAll(selector)

在原先元素后面的兄弟元素中,選取匹配selector的元素。若不設(shè)置參數(shù),nextAll()等價于nextAll(“*”),選取原先元素后面的所有兄弟元素

$(selector1).nextAll(selector2)≡$(selector1~selector2)

prevAll(selector)

在原先元素前面的兄弟元素中,選取匹配selector的元素。若不設(shè)置參數(shù),prevAll()等價于prevAll(“*”),選取原先元素前面的所有兄弟元素

siblings(selector)

在原先元素的兄弟元素中,選取匹配selector的元素。若不設(shè)置參數(shù),siblings()等價于siblings(“*”),選取原先元素的所有兄弟元素

nextUntil(selector)

選取原先元素后面的兄弟元素,直到遇到匹配selector的元素為止,且不包括該元素。若不設(shè)置參數(shù),nextUntil()等價于nextAll(),選取原先元素后面的所有兄弟元素

prevUntil(selector)

選取原先元素前面的兄弟元素,直到遇到匹配selector的元素為止,且不包括該元素。若不設(shè)置參數(shù),prevUntil()等價于prevAll(),選取原先元素前面的所有兄弟元素

?

更改為更多元素集合

方法?????????????

描述

等價

add(selector)

在原先元素的基礎(chǔ)上添加選取匹配selector的元素

$(selector1).add(selector2)≡$(selector1,selector2)

andSelf()

更改為后代元素、祖先元素、兄弟元素的這些操作,會在原先元素以外選取元素??捎糜趯⒃仍睾透牟僮鬟x取的元素合并在一起

is changed to a collection of partial elements

方法?????????????

描述

等價

eq(index)

在原先元素中篩選索引值等于index的元素,索引值從0開始正數(shù),也可以從-1開始倒數(shù),但不能混用

$(selector).eq(index)≡$(selector:eq(index))

first()

在原先元素中篩選第一個元素,等同于eq(0)

$(selector).first()≡$(selector:first)

last()

在原先元素中篩選最后一個元素,等同于eq(-1)

$(selector).last()≡$(selector:last)

slice(start,[end])

在原先元素中篩選索引值從start到end-1的元素。若不傳入end,則篩選索引值大于等于start的元素

filter(selector)

在原先元素中篩選匹配selector的元素

filter(fn(index))

使用函數(shù)篩選,對于索引值等于index的元素,若函數(shù)返回true,該元素包含在篩選集合中,否則排除在外

可實現(xiàn)$(selector:even(index))、$(selector:odd(index))、

$(selector:gt(index))、

$(selector:lt(index))等

not(selector)

在原先元素中篩選不匹配selector的元素

$(selector1).not(selector2)≡$(selector1:not(selector2))

not(fn(index))

使用函數(shù)篩選,對于索引值等于index的元素,若函數(shù)返回true,該元素排除在篩選集合外,否則包含在內(nèi)

可實現(xiàn)$(selector:even(index))、$(selector:odd(index))、

$(selector:gt(index))、

$(selector:lt(index))等

has(selector)

在原先元素中篩選出擁有匹配selector后代元素的元素

$(selector1).has(selector2)≡$(selector1:has(selector2))

Method???????????????????????????????????????????????????????

Description

Equivalent

方法?????????????

描述

end()

使執(zhí)行更改jQuery對象操作后的選取元素還原到更改之前。若希望還原多個更改操作,則多次調(diào)用,直到最后會返回空集

eq(index) Select the elements whose index value is equal to index among the original elements. The index value starts from 0 as a positive number, or it can count down from -1, but it cannot be mixed $(selector).eq(index)≡$(selector:eq(index))
first() Select the first element among the original elements, which is equivalent to eq(0) $(selector).first()≡$(selector:first)
last() Select the last element among the original elements, which is equivalent to eq(-1) $(selector).last()≡$(selector:last)
slice(start,[end]) Select elements with index values ??from start to end-1 in the original elements. If end is not passed in, elements with index values ??greater than or equal to start will be filtered
filter(selector) Filter elements matching the selector from the original elements
filter(fn(index)) Use function filtering. For elements whose index value is equal to index, if the function returns true, the element is included in the filtered collection, otherwise it is excluded Can realize $(selector:even(index)), $(selector:odd(index)), $(selector:gt(index))、 $(selector:lt(index)) etc.
not(selector) Filter elements that do not match the selector from the original elements $(selector1).not(selector2)≡$(selector1:not(selector2))
not(fn(index)) Use function filtering. For elements whose index value is equal to index, if the function returns true, the element will be excluded from the filtered collection, otherwise it will be included Can realize $(selector:even(index)), $(selector:odd(index)), $(selector:gt(index))、 $(selector:lt(index)) etc.
has(selector) Filter out elements that have descendant elements that match the selector from the original elements $(selector1).has(selector2)≡$(selector1:has(selector2))
Restore jQueryObject
Method??????????????????????????????????????????????????????? Description
end() Restore the selected elements after changing the jQuery object to before the change. If you want to restore multiple change operations, call it multiple times until an empty set is returned in the end
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

4 steps to change user folder names on Windows 11 4 steps to change user folder names on Windows 11 Jul 07, 2023 pm 02:33 PM

User folder names and account names are set during user account setup. However, sometimes for some reason, you need to change your user folder name on Windows 11. Unlike renaming a standard folder, this process is not that simple. But with the right information, the process can be effortless, and that's what we've got you covered in this guide. Is it safe to rename my user folder name? As mentioned before, changing user folder names on Windows 11 is not as simple as renaming a normal folder. Even if you change the user account name, the user folder name will remain the same. Microsoft recommends not changing your user folder name as this may cause some applications to

How to change the storage location of wallpaper engine? How to set the save path in wallpaper engine How to change the storage location of wallpaper engine? How to set the save path in wallpaper engine Mar 13, 2024 pm 12:40 PM

Many users like to download various wallpapers and videos on WallpaperEngine. Over time, they will find that more and more wallpapers are downloaded, resulting in insufficient hard disk space. At this time, the storage location of WallpaperEngine can be changed to reduce the space occupied. So let’s take a look at how to change the save path for wallpaperengine. Step 1: Click Settings under steam in the upper left corner to open the following interface. Step 2: Click Download to find the "Steam Library Folder" under the content library, and click Open above. Step 3: Click Add Library Folder, select the path you want to change to, and after adding it, right-click on the default column.

How to adjust the font, style, and size of Notepad in Windows 11 How to adjust the font, style, and size of Notepad in Windows 11 Sep 23, 2023 pm 11:25 PM

Many users want to change the font in Notepad on Windows 11 because the default font is too small or difficult to read for them. Changing fonts is quick and easy, and in this guide, we'll show you how to customize Notepad and change the font to suit your needs. What font does Windows 11 Notepad use by default? As for the default font options, Notepad uses the Consolas font and the default font size is set to 11 pixels. How to change Notepad font size and style in Windows 11? Use the Edit menu in Notepad to click the search button and type notepad. Select Notepad from the list of results. In Notepad, click the Edit menu and select Fonts. You should now see the settings in the left pane

How to change the font color of win7 desktop icons How to change the font color of win7 desktop icons Jan 02, 2024 pm 11:17 PM

The default desktop icon font of win7 is generally white. If we use a white desktop background, the desktop icon text may not be visible. At this time, we can customize the desktop font color through the advanced appearance settings in the personalization settings. The following is Let’s take a look together. Tutorial on changing the font color of win7 desktop icons 1. Right-click a blank space on the desktop and open the "Personalization" settings. 2. Under Theme, we can directly select the desired theme to change the font color of desktop icons. 3. If you are not satisfied with these themes, you can also turn on the "Window Color" as shown in the picture. 4. Click "Advanced Appearance Settings" below 5. Change the "Project" at the icon location to "Desktop" 6. Then you can change various attributes such as font color and size in the red box

Step-by-step guide to changing background color with Eclipse Step-by-step guide to changing background color with Eclipse Jan 28, 2024 am 08:28 AM

Teach you step by step how to change the background color in Eclipse, specific code examples are required Eclipse is a very popular integrated development environment (IDE) that is often used to write and debug Java projects. By default, the background color of Eclipse is white, but some users may wish to change the background color to suit their preference or to reduce eye strain. This article will teach you step by step how to change the background color in Eclipse and provide specific code examples. Step 1: Open Eclipse First

Fix: Alt + Shift doesn't change language on Windows 11 Fix: Alt + Shift doesn't change language on Windows 11 Oct 11, 2023 pm 02:17 PM

While Alt+Shift doesn't change the language on Windows 11, you can use Win+Spacebar to get the same effect. Also, make sure to use the left Alt+Shift and not the ones on the right side of the keyboard. Why can't Alt+Shift change the language? You have no more languages ??to choose from. Input language hotkeys have been changed. A bug in the latest Windows update prevents you from changing your keyboard language. Uninstall the latest updates to resolve this issue. You are in the active window of an application that uses the same hotkeys to perform other actions. How do you use AltShift to change the language on Windows 11? 1. Use the correct key sequence First, make sure you are using the correct method of using the + combination.

How to change region settings on xbox store How to change region settings on xbox store Dec 24, 2023 pm 08:53 PM

When the game you want to buy is not available, you can purchase it by changing the region. Do any players know how to change the region settings in the Xbox store? So let’s take a look at the introduction to changing the region settings in the Xbox store! Xbox store region settings: 1. Open windows settings - select time and language. 2. Select the region - the default should be China - select other countries and regions. 3. Select other countries and regions - enter the store - the store prompts you to refresh the content.

Teach you how to modify the temporary file location of Win7 Teach you how to modify the temporary file location of Win7 Jan 04, 2024 pm 11:25 PM

The temp folder is our temporary file storage location. The system will save temporary files to this folder. If there are too many temporary files, especially when the temp folder is on the system disk, it is likely to affect the system running speed. We can solve the problem by changing the temp location. Let’s take a look below. Tutorial on changing the location of win7temp 1. First, right-click "Computer" and open "Properties" 2. Click "Advanced System Settings" on the left 3. Click "Environment Variables" below 4. Select "temp" and click "Edit" 5. Then change Just change the "Variable Value" to the path that needs to be changed.

See all articles