jQuery對html元素取值與賦值

Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區域: $("#text_id").attr("value",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容
Jquery給基本控件的取值、賦值


TEXTBOX: 
var str = $('#txt').val();


 $('#txt').val("Set Lbl Value"); 


1.//文本框,文本區域:
2.$("#text_id").attr("value",'');//清空內容
3.$("#text_id").attr("value",'test');// 填充內容
LABLE:   


var str = $('#lbl').text();


$('#lbl').text("Set Lbl Value");


1.   var valradio = $("input[@type=radio][@checked]").val();
2.   var item = $('input[@name=items][@checked]').val();
3.var checkboxval = $("#checkbox_id").attr("value");
4.   var selectval = $('#select_id').val();
1.//多選框checkbox:
2.$("#chk_id").attr("checked",'');//使其未勾選
3.$("#chk_id").attr("checked",true);// 勾選
4.if($("#chk_id").attr('checked')==true) //判斷是否已經選中
1.單選組radio:
2. 
3.$("input[@type=radio]").attr("checked",'2'); //設置value=2的項目爲當前選中項
4. 
5.//下拉框select:
6.$("#select_id").attr("value",'test');// 設置value=test的項目爲當前選中項
7.$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
8.$("#select_id").empty();//清空下拉框
9. 
10.獲取一組名爲 (items)的radio被選中項的值
11.var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
12.獲 取select被選中項的文本
13.var item = $("select[@name=items] option[@selected]").text();
14.select下拉框的第二個元素爲當前選中值
15.$('#select_id')[0].selectedIndex = 1;
16.radio單選組的第二個元素爲當前選中值
17.$('input[@name=items]').get(1).checked = true;
18. 
19.//重置表單
20.$("form").each(function(){
21.   .reset();
22.});
摘要: Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區域: $("#text_id").attr("value",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容
Jquery給基本控件的取值、賦值


TEXTBOX: 
var str = $('#txt').val();


 $('#txt').val("Set Lbl Value"); 


1.//文本框,文本區域:
2.$("#text_id").attr("value",'');//清空內容
3.$("#text_id").attr("value",'test');// 填充內容
LABLE:   


var str = $('#lbl').text();


$('#lbl').text("Set Lbl Value");


1.   var valradio = $("input[@type=radio][@checked]").val();
2.   var item = $('input[@name=items][@checked]').val();
3.var checkboxval = $("#checkbox_id").attr("value");
4.   var selectval = $('#select_id').val();
1.//多選框checkbox:
2.$("#chk_id").attr("checked",'');//使其未勾選
3.$("#chk_id").attr("checked",true);// 勾選
4.if($("#chk_id").attr('checked')==true) //判斷是否已經選中
1.單選組radio:
2. 
3.$("input[@type=radio]").attr("checked",'2'); //設置value=2的項目爲當前選中項
4. 
5.//下拉框select:
6.$("#select_id").attr("value",'test');// 設置value=test的項目爲當前選中項
7.$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
8.$("#select_id").empty();//清空下拉框
9. 
10.獲取一組名爲 (items)的radio被選中項的值
11.var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
12.獲 取select被選中項的文本
13.var item = $("select[@name=items] option[@selected]").text();
14.select下拉框的第二個元素爲當前選中值
15.$('#select_id')[0].selectedIndex = 1;
16.radio單選組的第二個元素爲當前選中值
17.$('input[@name=items]').get(1).checked = true;
18. 
19.//重置表單
20.$("form").each(function(){

21.   .reset();

22. )};


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章