jquery 取值賦值

2021-10-11 07:42:34 字數 2077 閱讀 6813

文字框操作

取值:$("#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();

$("input[type='radio']:checked").

val();

$('input:radio:checked').

val();

$("input[name='name_r']:checked").

val();

//一組$(

":radio[checked]").

each

(function

(radio))$

('input[name="name_c"]:checked').

each

(function()

);

選中

$

("#check_id[value=val]").

attr

("checked"

,true);

//選擇$(

"#check_id[value=val]").

attr

("checked",""

);//取消選擇$(

"#check_id[value=val]").

attr

("checked"

,false);

//取消選擇$(

"#check_id[value=val]").

removeattr

("checked");

//取消選擇

下拉框

取值(選中):

$

("#selector").

val();

$("#select option[selected]").

text()

;$("#select option:selected").

text()

;$("#select").

find

("option:selected").

text()

;

賦值/選中

$

("#selector").

val(

"value");

$("#selector").

find

("option:contains('value')").

attr

("selected"

,true

);

新增

$

('red').

($("#select"))

;$("#select").

('red'

);

清空

$

("#select").

empty()

;$("#select").

html(""

);

元素可用不可用

$

("#id").

attr

("disabled"

,false);

//設為可用$(

"#id").

attr

("disabled"

,true);

//設為不可用

表單重置

$

('#form_q')[

0].reset()

;$(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取值賦值

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...

Jquery表單取值賦值

jquery表單取值賦值的一些基本操作2008 12 25 03 17 獲得text.areatext的值 var textval text id attr value 或者 var textval text id val 獲取單選按鈕的值 var valradio input type radio...