- 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",\'\');//未选中的值
- $("input[@type=checkbox][@checked]").val();//得到复选框的选中的第一项的值,要注意jquery-1-2-6是这样的标准,而jquery-1.3-2中是不一样的标准,应该这么写:$("input[type=checkbox][checked]").val();
- $("input[@type=checkbox][@checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出
alert($(this).val());
}); - $("#chk_id").attr("checked",true);//选中的值
- if($("#chk_id").attr(\'checked\')==undefined) //判断是否已经选中
- //单选组radio:
- $("input[@type=radio]").attr("checked",\'10\');//设置value=10的单选按钮为当前选中项
- $(\'input[@name=items]\').get(1).checked = true; //radio单选组的第二个元素为当前选中值
- if($("input:radio:checked").length>0)//判断是否选中
- 或者if($("input[@type=radio][@name=xxx][@checked]").val()==undefined)
- //下拉框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();//清空下拉框
- var item = $("select[@name=items] option[@selected]").text(); //获取select被选中项的文本
- $(\'#select_id\')[0].selectedIndex = 1; //select下拉框的第二个元素为当前选中值
- //遍历option和添加、移除option
-
//取得下拉选单的选取值
$(#testSelect option:selected\').text();
或$("#testSelect").find(\'option:selected\').text();
或$("#testSelect").val(); - function changeShipMethod(shipping){
var len = $("select[@name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[@name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value=\'111\'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
}
} - $("#select_id").val()==-1 //判断是否选中