2 下常用的方法

2022-09-16 13:18:14 字數 2482 閱讀 6436

$()下的常用方法

has() 包含

not() 與filter相反

filter() 過濾

next() 下乙個兄弟節點

prev() 上乙個兄弟節點

fild() 尋找子級節點

eq() 一組元素中的第幾個

index() 一組元素中的索引

attr() 設定元素 class屬性或樣式

//filter:過濾

//not:過濾的反義詞

//--針對本身元素

$('div').filter('.box'); //

選中帶有class屬性為box的div標籤

$('div').not('.box'); //

選中不包含[class="box"]屬性的標籤

html:

//has:包含

//--針對子元素

$('div').has('span'); //

包含span元素的 div元素

【易錯】$('div').has('.box'); //

子元素擁有[class='box']屬性的 div元素

html:

//next() 下乙個兄弟'節點'[其餘元素]

//prev() 上乙個兄弟'節點'[其餘元素]

$('div').next(); //

html頁面所有div元素的下乙個兄弟節點

$('div').prev(); //

html頁面所有div元素的上乙個兄弟節點

html:

//find:找到

$('div').find('h2'); //

找到div元素下的【所有】h2元素

html:

//eq() 一組元素的第幾個,從0開始計數

$('div').eq(0); //

一組div元素 當中的【第乙個】div元素

//index: 索引

$('#h').index() //

2 當前元素在所有【兄弟節點】中的位置

//attr() 設定或返回被選中的屬性值

$(selector).attr(attribute); //

selector 元素 attribute屬性

【特殊】$(selector).attr(attribute,value[or function(index,oldvalue)]); //

value 屬性值 or 返回屬性值的函式,該函式接受並使用選擇器的index值以及索引值

$(selector).attr() //

規定多個屬性/值對

【易忘】$(selector).attr('class','active'); //

設定元素的class屬性

製作乙個選項卡--

doctype html

>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>

title

>

<

style

type

="text/css"

>

#div1 div

.active

style

>

head

>

<

body

>

<

script

src="js/jquery-2.1.0.js"

>

script

>

<

div

id="div1"

>

<

input

class

="active"

type

="button"

value

="1"

>

<

input

type

="button"

value

="2"

>

<

input

type

="button"

value

="3"

>

<

div>1111

div>

<

div>2222

div>

<

div>3333

div>

div>

<

script

>

$(function

());

})script

>

body

>

html

>

jquery常用的方法2

3 prepend content 向每個匹配的元素內部前置內容。ex html i would like to say jquery p prepend hello 結果 helloi would like to say 4 pretendto content 實際上,使用這個方法是顛倒了常規的 ...

ubuntu下常用的命令(2)

1.sudo apt get install 軟體名 安裝軟體的命令。2.sudo nautilus 開啟檔案 有root許可權 3.su root 切換到 root 4.useradd 使用者名稱 建立乙個新的使用者。adduser 使用者名稱 也是建立乙個新的使用者,更適用於初學者,是互動方式的...

re模組下的的常用方法

引入模組 import re 1.查詢 findall 匹配所有,每一項都是列表中的乙個元素 ret re.findall d sjkhk172按實際花費928 print ret 172 928 search 只匹配從左到右的第乙個,得到的不是結果,而是乙個變數,通過這個變數的group方法來獲取...