jQuery對表單元素的取值和賦值操作代碼
更新時間:2011年05月19日 21:27:08 作者:
使用常規(guī)的思路:$(“#keyword”).value 取值是取不到的,因為此時$(‘#keydord’)已經(jīng)不是個element,而是個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被選中項的值*/
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的項目為當(dāng)前選中項
/*下拉框select*/
$("#select_id").attr("value",'test');//設(shè)置value=test的項目為當(dāng)前選中項
$("testtest2").appendTo("#select_id")//添加下拉框的option
$("#select_id").empty();//清空下拉框
/*獲取一組名為(items)的radio被選中項的值*/
var item = $('input[name=items]:checked').val(); //若未被選中 則val() = undefined
/*獲取select被選中項的文本*/
var item = $("select[name=items] option:selected").text();
/*select下拉框的第二個元素為當(dāng)前選中值*/
$('#select_id')[0].selectedIndex = 1;
/*radio單選組的第二個元素為當(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的項目為當(dāng)前選中項
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項目為當(dāng)前選中項
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當(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的項目為當(dāng)前選中項
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項目為當(dāng)前選中項
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當(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被選中項的值*/
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的項目為當(dāng)前選中項
/*下拉框select*/
$("#select_id").attr("value",'test');//設(shè)置value=test的項目為當(dāng)前選中項
$("testtest2").appendTo("#select_id")//添加下拉框的option
$("#select_id").empty();//清空下拉框
/*獲取一組名為(items)的radio被選中項的值*/
var item = $('input[name=items]:checked').val(); //若未被選中 則val() = undefined
/*獲取select被選中項的文本*/
var item = $("select[name=items] option:selected").text();
/*select下拉框的第二個元素為當(dāng)前選中值*/
$('#select_id')[0].selectedIndex = 1;
/*radio單選組的第二個元素為當(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的項目為當(dāng)前選中項
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項目為當(dāng)前選中項
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當(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的項目為當(dāng)前選中項
//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置value=test的項目為當(dāng)前選中項
$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")//添加下拉框的 option
$("#select_id").empty();//清空下拉框
獲取一組名為 (items)的radio被選中項的值
var item = $('input[@name=items][@checked]').val();//若未被選中 則val() = undefined
獲 取select被選中項的文本
var item = $("select[@name=items] option[@selected]").text();
select下拉框的第二個元素為當(dāng)前選中值
$('#select_id')[0].selectedIndex = 1;
radio單選組的第二個元素為當(dāng)前選中值
$('input[@name=items]').get(1).checked = true;
//重置表單
$("form").each(function(){
.reset();
});
您可能感興趣的文章:
- jQuery操作動畫完整實例分析
- jQuery操作事件完整實例分析
- jQuery操作元素追加內(nèi)容示例
- JQuery使用屬性addClass、removeClass和toggleClass實現(xiàn)增加和刪除類操作示例
- JS 遍歷 json 和 JQuery 遍歷json操作完整示例
- jquery validate 實現(xiàn)動態(tài)增加/刪除驗證規(guī)則操作示例
- jQuery實現(xiàn)checkbox全選、反選及刪除等操作的方法詳解
- 使用jQuery操作Cookies的實現(xiàn)代碼
- JQuery對checkbox操作 (循環(huán)獲取)
- jquery.cookie.js 操作cookie實現(xiàn)記住密碼功能的實現(xiàn)代碼
- 新手學(xué)習(xí)JQuery基本操作和使用案例解析
相關(guān)文章
jQuery刪除/清空指定元素的所有子節(jié)點實例代碼
這篇文章主要給大家介紹了關(guān)于jQuery刪除/清空指定元素的所有子節(jié)點,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用jQuery具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07jQuery+Ajax+PHP+Mysql實現(xiàn)分頁顯示數(shù)據(jù)實例講解
這是一個典型的Ajax應(yīng)用,在頁面上,您只需要點擊“下一頁”,數(shù)據(jù)區(qū)將自動加載對應(yīng)頁碼的數(shù)據(jù),重新刷新數(shù)據(jù)區(qū)。類似的效果在很多網(wǎng)站上應(yīng)用,尤其在一些需要展示大量圖片數(shù)據(jù)的網(wǎng)頁如淘寶商品列表頁,Ajax分頁效果讓您的網(wǎng)站數(shù)據(jù)加載顯得非常流暢。2015-09-09