
本文实例讲述了jQuery对html元素的取值与赋值方法。分享给大家供大家参考,具体如下:
Jquery给基本控件的取值、赋值
TEXTBOX:
var str = $(#txt).val();
$(#txt).val(“Set Lbl Value”);
//文本框,文本区域:
$(“#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) //判断是否已经选中
单选组radio:
$(“input[@type=radio]”).attr(“checked”,2); //设置value=2的项目为当前选中项
下拉框select:
$(“#select_id”).attr(“value”,test);// 设置value=test的项目为当前选中项
$(“