亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jQuery對html元素取值與賦值的方法

 更新時間:2013年11月20日 15:45:39   作者:  
這篇文章主要介紹了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)容

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的項目為當前選中項

//下拉框select:
$("#select_id").attr("value",'test');// 設(shè)置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();
});

相關(guān)文章

最新評論