jQuery的取值與賦值

2021-10-06 06:15:02 字數 1720 閱讀 8545

取值 賦值相關的方法

//取值

console.

log($(

'ul li').

html()

)//返回值型別是string,在乙個框中去值html是只拿第乙個值,特殊的

console.

log($(

'ul').

get(0)

.innerhtml)

//賦值$(

'ul li').

html

('9'

)//賦值是全部賦值

//取值:取得是文字節點

console.

log($(

'ul li').

text()

);//賦值$(

'ul li').

text

('9')$

('ul li').

text

(function

(index,ele)`;

})

$

('ul li').

size()

;$('ul li'

).length;

$

('.btn').

click

(function()

);

//賦值$(

'.demo').

css().

css()$

('.demo').

css(

'width'

,'100px').

css(

'height'

,'100px').

css(

'backgroundcolor'

,'red'

)//取值

console.

log($(

'.demo').

css(

'backgroundcolor'

))

//取值

console.

log($(

'.demo').

attr

('class'))

console.

log($(

'input').

attr

('checked'))

//賦值$(

'.demo').

attr

('id'

,'test')$

('input').

attr

('checked'

,'123')$

('div').

attr

('log'

,'yaya'

)

$

('input[type=checkbox]').

prop

('checked'

,true

)

$

('.btn').

click

(function()

);$(

'.btn').

click

(function()

);

JQuery 取值賦值

input type text name textname id text id value 取值等等 function get form value 對表單的其他處理 控制表單元素 文字框,文字區域 text id attr value 清空內容 text id attr value test 填...

jquery 取值賦值

文字框操作 取值 text id attr value text id val input type text val 清除 text id attr value 賦值 text id attr value 123 單選框操作 取值 input type radio checked val inpu...

jquery取值賦值

a val 1 id為a的值就是1了 jquery中都這樣,賦值的時候作為引數傳給函式,和單純的js有區別,像 a html 1 a text 1 都是賦值 a html a text 都是取值,取html,取text文字 nput class required 查詢出所有input標籤,且clas...