function get_form_value(){
/*获得TEXT.AREATEXT的值*/
var textval = $("#text_id").attr("value");//或者
var textval = $("#text_id").val();
/*获取单选按钮的值*/
var valradio = $("input[@type=radio][@checked]").val();
/*获取复选框的值*/
var checkboxval = $("#checkbox_id").attr("value");
/*获取下拉列表的值*/
var selectval = $('#select_id').val();
}
//控制表单元素:
//文本框,文本区域:
$("#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();//清空下拉框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function CheckedHandler(){
var strVal = [];
$(":checked").each(function(){
strVal.push($(this).val());
});
$("#txtcheckbox").val(strVal);
alert(strVal.length + " " + strVal);
}
</script>
</head>
<body>
<table>
<tr>
<tr>
<td height="30">
<input type="checkbox" class="chbox" value="有风度" /><label>有风度</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="威严" /><label>威严</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="亲切" /><label>亲切</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="血性汉子" /><label>血性汉子</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="小白脸" /><label>小白脸</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="绅士气质" /><label>绅士气质</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="肤白" /><label>肤白</label>
</td>
</tr>
<tr>
<td>
<input type="checkbox" class="chbox" value="黝黑" /><label>黝黑</label>
</td>
</tr>
<td>
<input id="txtcheckbox" type="text" />
<input name="btn" type="button" onclick="CheckedHandler();" value="提交" />
</td>
</table>
</body>
</html>
下一篇:js删除字符串中非数字的字符