獲取一組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;javascript
獲取值:html
文本框,文本區域:$("#txt").attr("value");
多選框checkbox:$("#checkbox_id").attr("value");
單選組radio: $("input[@type=radio][@checked]").val();
下拉框select: $('#sel').val();java
控制表單元素:
文本框,文本區域:$("#txt").attr("value",'');//清空內容
$("#txt").attr("value",'11');//填充內容jquery
多選框checkbox: $("#chk1").attr("checked",'');//不打勾
$("#chk2").attr("checked",true);//打勾
if($("#chk1").attr('checked')==undefined) //判斷是否已經打勾app
單選組radio: $("input[@type=radio]").attr("checked",'2');//設置value=2的項目爲當前選中項
下拉框select: $("#sel").attr("value",'-sel3');//設置value=-sel3的項目爲當前選中項
$("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的option
$("#sel").empty();//清空下拉框ide
$("input[@type=radio][@name='gender'][@checked]").val()
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
/**//*得到TEXT.AREATEXT的值*/
var textval = $("#text_id").attr("value");//或者
var textval = $("#text_id").val();
![](http://static.javashuo.com/static/loading.gif)
/**//*獲取單選按鈕的值*/
var valradio = $("input[@type=radio][@checked]").val();
![](http://static.javashuo.com/static/loading.gif)
/**//*獲取複選框的值*/
var checkboxval = $("#checkbox_id").attr("value");
![](http://static.javashuo.com/static/loading.gif)
/**//*獲取下拉列表的值*/
var selectval = $('#select_id').val();
}
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
3.另外對錶單的其餘處理:
![](http://static.javashuo.com/static/loading.gif)
JavaScript代碼
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
//控制表單元素:
//文本框,文本區域:
$("#text_id").attr("value",'');//清空內容
$("#text_id").attr("value",'test');//填充內容
//多選框checkbox:
$("#chk_id").attr("checked",'');//未選中的值
$("#chk_id").attr("checked",true);//選中的值
if($("#chk_id").attr('checked')==undefined) //判斷是否已經選中
//單選組radio:
$("input[@type=radio]").attr("checked",'10');//設置value=10的單選按鈕爲當前選中項
//下拉框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();//清空下拉框
![](http://static.javashuo.com/static/loading.gif)
jquery radio取值,checkbox取值,select取值,radio選中,checkbox選中,select選中,及其相關
獲取一組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;
![](http://static.javashuo.com/static/loading.gif)
獲取值:
![](http://static.javashuo.com/static/loading.gif)
文本框,文本區域:$("#txt").attr("value");
多選框checkbox:$("#checkbox_id").attr("value");