jQuery對表單元素的取值和賦值操作代碼
更新時(shí)間:2011年05月19日 21:27:08 作者:
使用常規(guī)的思路:$(“#keyword”).value 取值是取不到的,因?yàn)榇藭r(shí)$(‘#keydord’)已經(jīng)不是個(gè)element,而是個(gè)jquery對象,所以應(yīng)該使用:$(“#keyword”).val()
$("#keyword")[0].value = "";
/*獲得TEXT.AREATEXT的值*/
var textval = $("#text_id").attr("value");
//或者
var textval = $("#text_id").val();
/*獲取單選按鈕的值*/
var valradio = $("input[type=radio]:checked").val();
/*獲取一組名為(items)的radio被選中項(xiàng)的值*/
var item = $('input[name=items]:checked').val();
/*獲取復(fù)選框的值*/
var checkboxval = $("#checkbox_id").attr("value");
/*獲取下拉列表的值*/
var selectval = $('#select_id').val();
/*文本框,文本區(qū)域*/
$("#text_id").attr("value",");//清空內(nèi)容
$("#text_id").attr("value",'test');//填充內(nèi)容
/*多選框checkbox*/
$("#chk_id").attr("checked",");//使其未勾選
$("#chk_id").attr("checked",true);//勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
/*單選組radio*/
$("input[type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
/*下拉框select*/
$("#select_id").attr("value",'test');//設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("testtest2").appendTo("#select_id")//添加下拉框的option
$("#select_id").empty();//清空下拉框
/*獲取一組名為(items)的radio被選中項(xiàng)的值*/
var item = $('input[name=items]:checked').val(); //若未被選中 則val() = undefined
/*獲取select被選中項(xiàng)的文本*/
var item = $("select[name=items] option:selected").text();
/*select下拉框的第二個(gè)元素為當(dāng)前選中值*/
$('#select_id')[0].selectedIndex = 1;
/*radio單選組的第二個(gè)元素為當(dāng)前選中值*/
$('input[name=items]').get(1).checked = true;
/*重置表單*/
$("form").each(function(){
.reset();
});
jQuery對html元素取值與賦值
Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內(nèi)容 $("#text_id").attr("value",'test');// 填充內(nèi)容
Jquery給基本控件的取值、賦值
TEXTBOX:
var str = $('#txt').val();
$('#txt').val("Set Lbl Value");
//文本框,文本區(qū)域:
$("#text_id").attr("value",'');//清空內(nèi)容
$("#text_id").attr("value",'test');// 填充內(nèi)容
LABLE:
var str = $('#lbl').text();
$('#lbl').text("Set Lbl Value");
var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//多選框checkbox:
$("#chk_id").attr("checked",'');//使其未勾選
$("#chk_id").attr("checked",true);// 勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
單選組radio:
$("input[@type=radio]").attr("checked",'2'); //設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(function(){
.reset();
});
摘要: Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內(nèi)容 $("#text_id").attr("value",'test');// 填充內(nèi)容
Jquery給基本控件的取值、賦值
TEXTBOX:
var str = $('#txt').val();
$('#txt').val("Set Lbl Value");
//文本框,文本區(qū)域:
$("#text_id").attr("value",'');//清空內(nèi)容
$("#text_id").attr("value",'test');// 填充內(nèi)容
LABLE:
var str = $('#lbl').text();
$('#lbl').text("Set Lbl Value");
var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//多選框checkbox:
$("#chk_id").attr("checked",'');//使其未勾選
$("#chk_id").attr("checked",true);// 勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
單選組radio:
$("input[@type=radio]").attr("checked",'2'); //設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(function(){
.reset();
});
/*獲得TEXT.AREATEXT的值*/
var textval = $("#text_id").attr("value");
//或者
var textval = $("#text_id").val();
/*獲取單選按鈕的值*/
var valradio = $("input[type=radio]:checked").val();
/*獲取一組名為(items)的radio被選中項(xiàng)的值*/
var item = $('input[name=items]:checked').val();
/*獲取復(fù)選框的值*/
var checkboxval = $("#checkbox_id").attr("value");
/*獲取下拉列表的值*/
var selectval = $('#select_id').val();
/*文本框,文本區(qū)域*/
$("#text_id").attr("value",");//清空內(nèi)容
$("#text_id").attr("value",'test');//填充內(nèi)容
/*多選框checkbox*/
$("#chk_id").attr("checked",");//使其未勾選
$("#chk_id").attr("checked",true);//勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
/*單選組radio*/
$("input[type=radio]").attr("checked",'2');//設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
/*下拉框select*/
$("#select_id").attr("value",'test');//設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("testtest2").appendTo("#select_id")//添加下拉框的option
$("#select_id").empty();//清空下拉框
/*獲取一組名為(items)的radio被選中項(xiàng)的值*/
var item = $('input[name=items]:checked').val(); //若未被選中 則val() = undefined
/*獲取select被選中項(xiàng)的文本*/
var item = $("select[name=items] option:selected").text();
/*select下拉框的第二個(gè)元素為當(dāng)前選中值*/
$('#select_id')[0].selectedIndex = 1;
/*radio單選組的第二個(gè)元素為當(dāng)前選中值*/
$('input[name=items]').get(1).checked = true;
/*重置表單*/
$("form").each(function(){
.reset();
});
jQuery對html元素取值與賦值
Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內(nèi)容 $("#text_id").attr("value",'test');// 填充內(nèi)容
Jquery給基本控件的取值、賦值
TEXTBOX:
var str = $('#txt').val();
$('#txt').val("Set Lbl Value");
//文本框,文本區(qū)域:
$("#text_id").attr("value",'');//清空內(nèi)容
$("#text_id").attr("value",'test');// 填充內(nèi)容
LABLE:
var str = $('#lbl').text();
$('#lbl').text("Set Lbl Value");
var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//多選框checkbox:
$("#chk_id").attr("checked",'');//使其未勾選
$("#chk_id").attr("checked",true);// 勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
單選組radio:
$("input[@type=radio]").attr("checked",'2'); //設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(function(){
.reset();
});
摘要: Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內(nèi)容 $("#text_id").attr("value",'test');// 填充內(nèi)容
Jquery給基本控件的取值、賦值
TEXTBOX:
var str = $('#txt').val();
$('#txt').val("Set Lbl Value");
//文本框,文本區(qū)域:
$("#text_id").attr("value",'');//清空內(nèi)容
$("#text_id").attr("value",'test');// 填充內(nèi)容
LABLE:
var str = $('#lbl').text();
$('#lbl').text("Set Lbl Value");
var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]').val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//多選框checkbox:
$("#chk_id").attr("checked",'');//使其未勾選
$("#chk_id").attr("checked",true);// 勾選
if($("#chk_id").attr('checked')==true) //判斷是否已經(jīng)選中
單選組radio:
$("input[@type=radio]").attr("checked",'2'); //設(shè)置value=2的項(xiàng)目為當(dāng)前選中項(xiàng)
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項(xiàng)目為當(dāng)前選中項(xiàng)
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項(xiàng)的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項(xiàng)的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個(gè)元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個(gè)元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(function(){
.reset();
});
您可能感興趣的文章:
- jQuery操作動(dòng)畫完整實(shí)例分析
- jQuery操作事件完整實(shí)例分析
- jQuery操作元素追加內(nèi)容示例
- JQuery使用屬性addClass、removeClass和toggleClass實(shí)現(xiàn)增加和刪除類操作示例
- JS 遍歷 json 和 JQuery 遍歷json操作完整示例
- jquery validate 實(shí)現(xiàn)動(dòng)態(tài)增加/刪除驗(yàn)證規(guī)則操作示例
- jQuery實(shí)現(xiàn)checkbox全選、反選及刪除等操作的方法詳解
- 使用jQuery操作Cookies的實(shí)現(xiàn)代碼
- JQuery對checkbox操作 (循環(huán)獲取)
- jquery.cookie.js 操作cookie實(shí)現(xiàn)記住密碼功能的實(shí)現(xiàn)代碼
- 新手學(xué)習(xí)JQuery基本操作和使用案例解析
相關(guān)文章
jQuery.autocomplete 支持中文輸入(firefox)修正方法
jQuery.autocomplete 是jquery的流行插件,,能夠很好的實(shí)現(xiàn)輸入框的自動(dòng)完成(autocomplete)、建議提示(input suggest)功能,支持ajax數(shù)據(jù)加載。2011-03-03
用JQuery 判斷某個(gè)屬性是否存在hasAttr的解決方法
本篇文章介紹了,用JQuery 判斷某個(gè)屬性是否存在hasAttr的解決方法。需要的朋友參考下2013-04-04
jCallout 輕松實(shí)現(xiàn)氣泡提示功能
在提交表單前、焦點(diǎn)轉(zhuǎn)移后或者 keyup 時(shí)往往需要對輸入的文本就行檢驗(yàn),如果輸入內(nèi)容不符合相關(guān)約定則要進(jìn)行提示或警告,有一個(gè)叫 jCallout 的插件可以輕松實(shí)現(xiàn)該功能,該插件基于 jQuery 使用,所以使用前需要添加引用 jQuery2013-09-09
15個(gè)款優(yōu)秀的 jQuery 圖片特效插件推薦
這篇文章向大家推薦15個(gè)最佳 jQuery 圖片效果插件。jQuery是最流行的Javascript框架,使用簡單靈活,同時(shí)還有許多成熟的插件可供選擇2011-11-11
jquery $(this).attr $(this).val方法使用介紹
$(this).attr(key); 獲取節(jié)點(diǎn)屬性名的值,相當(dāng)于getAttribute(key)方法,本文整理了一些相關(guān)的示例,感興趣的朋友可以參考下2013-10-10
jQuery EasyUI API 中文文檔 - DataGrid數(shù)據(jù)表格
jQuery EasyUI API 中文文檔 - DataGrid數(shù)據(jù)表格使用說明,需要的朋友可以參考下。2011-11-11
jQuery學(xué)習(xí)筆記之jQuery構(gòu)建函數(shù)的7種方法
jQuery把所有的操作都包裝在一個(gè)jQuery()函數(shù)中,形成了統(tǒng)一(也是惟一)的操作入口,這為jQuery操作降低了門檻。那我們來看下具體構(gòu)造函數(shù)的“七種武器”吧。2014-06-06

