獲取一組radio被選中項的值
var item = $('input[@name=items][@checked]').val();
獲取select被選中項的文字
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當前選中值
$('#select_id')[0].selectedindex = 1;
radio單選組的第二個元素為當前選中值
$('input[@name=items]').get(1).checked = true;
獲取值:
文字框,文字區域:$("#txt").attr("value");$("#txt").val();
多選框checkbox:$("#checkbox_id").attr("value");
單選組radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();
控制表單元素:
文字框,文字區域:$("#txt").attr("value",'');//清空內容
$("#txt").attr("value",'11');//填充內容
多選框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判斷是否已經打勾
單選組radio: $("input[@type=radio]").attr("checked",'2');//設定value=2的專案為當前選中項 (錯)
$("input[@name=radio_s][@value=16]").attr("checked",true);(測試通過)
下拉框select: $("#sel").attr("value",'-sel3');//設定value=-sel3的專案為當前選中項
$("1111
$("#sel").empty();//清空下拉框
$("#select1")[0].options(index).selected = true; //使第index個option選中
$("#select1")[0].options(3).text //取索引為3的option值
jquery對表單元素的取值和賦值
獲得text的值 var textval text id attr value 或者 var textval text id val 獲取單選按鈕的值 var valraio input type raio checked val 獲取一組名為items的radio被選中項的值 var item i...
jquery對表單元素的取值和賦值
一 獲得text的值 txtval type text value longzhoufeng 二 獲取單選按鈕的值 三 獲取一組名為items的radio被選中項的值 四 獲取核取方塊的值 水果 chkbox name fruit type checkbox value 水果 五 獲取下拉列表的值 ...
Jquery獲取表單元素值 控制表單元素總結
function get form value 控制表單元素 文字框,文字區域 text id attr value 清空內容 text id attr value test 填充內容 多選框checkbox chk id attr checked 未選中的值 input type checkbox...