Jquery表單取值賦值

2021-05-10 01:50:37 字數 1450 閱讀 3373

jquery表單取值賦值的一些基本操作2008-12-25 03:17/*獲得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的專案為當前選中項

$("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 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...