常用html元素的取值和賦值方法總結 持續更新

2021-08-31 18:08:20 字數 1326 閱讀 3424

1.獲得type型別為text或者areatext的值

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

var textval = $("#text_id").val(); 

2.獲取單選按鈕的值 

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

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

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

4.獲取核取方塊的值 

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

5.獲取下拉列表的值

var selectval = $('#select_id').val(); 

6.文字框,文字區域

$("#text_id").attr("value",'');//清空內容 

$("#text_id").attr("value",'test');//填充內容 

7.多選框checkbox

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

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

if($("#chk_id").attr('checked')==true) //判斷是否已經選中 

8.單選組radio

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

9.下拉框select: 

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

$("test

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

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

11.獲取select被選中項的文字 

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

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

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

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

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

常用html元素的取值和賦值方法總結

1.獲得type型別為text或者areatext的值 var textval text id attr value var textval text id val 2.獲取單選按鈕的值 var valradio input type radio checked val 3.獲取一組名為 items...

jQuery對html元素取值與賦值

摘要 jquery給基本控制項的取值 賦值 textbox var str txt val txt val set lbl value 文字框,文字區域 text id attr value 清空內容 text id attr value test 填充內容 jquery給基本控制項的取值 賦值 t...

easyui radio 型別的取值和賦值方法

1.html 檔案 委託人證件型別 class easyui validatebox checked checked value 身份證 身份證 class easyui validatebox value 護照 護照 2.js的取值和賦值方法 取值方法 function checkradio 賦值...