Jquery表單取值賦值的一些基本操作

2021-08-24 22:52:05 字數 1370 閱讀 3704

/*獲得text.areatext的值*/

var textval = $(「#text_id」).attr(「value」);

//或者

var textval = $(「#text_id」).val();

/*獲取單選按鈕的值*/

var valradio = $(「input[@type=radio][@checked]「).val();

/*獲取一組名為(items)的radio被選中項的值*/

var item = $(『input[@name=items][@checked]『).val();

/*獲取核取方塊的值*/

var checkboxval = $(「#checkbox_id」).attr(「value」);

/*獲取下拉列表的值*/

var selectval = $(『#select_id』).val();

//文字框,文字區域:

$(「#text_id」).attr(「value」,」);//清空內容

$(「#text_id」).attr(「value」,』test』);//填充內容

//多選框checkbox:

$(「#chk_id」).attr(「checked」,」);//使其未勾選

$(「#chk_id」).attr(「checked」,true);//勾選

if($(「#chk_id」).attr(『checked』)==true) //判斷是否已經選中

//單選組radio:

$(「input[@type=radio]「).attr(「checked」,』2′);//設定value=2的專案為當前選中項

//下拉框select:

$(「#select_id」).attr(「value」,』test』);//設定value=test的專案為當前選中項

$(「#select_id」).empty();//清空下拉框

獲取一組名為(items)的radio被選中項的值

var item = $(『input[@name=items][@checked]『).val();//若未被選中 則val() = undefined

獲取select被選中項的文字

var item = $(「select[@name=items] option[@selected]「).text();

select下拉框的第二個元素為當前選中值

$(『#select_id』)[0].selectedindex = 1;

radio單選組的第二個元素為當前選中值

$(『input[@name=items]『).get(1).checked = true;

//重置表單

$(「form」).each(function());

Jquery表單取值賦值的一些基本操作

否 是我這樣寫的 input name jizai attr checked 0 設定value值為 0 的radio選中,不好用 jquery中,radio的選中與否是這麼設定的。rdo1 attr checked checked rdo1 removeattr checked jquery中,r...

Jquery表單取值賦值的一些基本操作

獲得text.areatext的值 var textval text id attr value 或者 var textval text id val 獲取單選按鈕的值 var valradio input type radio checked val 獲取一組名為 items 的radio被選中項...

Jquery表單取值賦值的一些基本操作

jquery表單取值賦值的一些基本操作 獲得text.areatext的值 vartextval text id attr value 或者 vartextval text id val 獲取單選按鈕的值 varvalradio input type radio checked val 獲取一組名為...