日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

jQuery对表单元素的取值和赋值操作代码

發(fā)布時間:2025/7/14 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jQuery对表单元素的取值和赋值操作代码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
使用常規(guī)的思路:$(“#keyword”).value 取值是取不到的,因為此時$(‘#keydord’)已經(jīng)不是個element,而是個jquery對象,所以應該使用:$(“#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(); /*獲取復選框的值*/ var checkboxval = $("#checkbox_id").attr("value"); /*獲取下拉列表的值*/ var selectval = $('#select_id').val(); /*文本框,文本區(qū)域*/ $("#text_id").attr("value",");//清空內容 $("#text_id").attr("value",'test');//填充內容 /*多選框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');//設置value=2的項目為當前選中項 /*下拉框select*/ $("#select_id").attr("value",'test');//設置value=test的項目為當前選中項 $("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下拉框的第二個元素為當前選中值*/ $('#select_id')[0].selectedIndex = 1; /*radio單選組的第二個元素為當前選中值*/ $('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",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容 Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容 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'); //設置value=2的項目為當前選中項 //下拉框select: $("#select_id").attr("value",'test');// 設置value=test的項目為當前選中項 $("<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下拉框的第二個元素為當前選中值 $('#select_id')[0].selectedIndex = 1; radio單選組的第二個元素為當前選中值 $('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",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容 Jquery給基本控件的取值、賦值 TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //文本框,文本區(qū)域: $("#text_id").attr("value",'');//清空內容 $("#text_id").attr("value",'test');// 填充內容 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'); //設置value=2的項目為當前選中項 //下拉框select: $("#select_id").attr("value",'test');// 設置value=test的項目為當前選中項 $("<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下拉框的第二個元素為當前選中值 $('#select_id')[0].selectedIndex = 1; radio單選組的第二個元素為當前選中值 $('input[@name=items]').get(1).checked = true; //重置表單 $("form").each(function(){ .reset(); });

?

總結

以上是生活随笔為你收集整理的jQuery对表单元素的取值和赋值操作代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。