Jquery 获取form表单text,areatext,radio,checkbox,select值

1.如何取form中的各种值

//获取text,areatext的值

var text_attr=$("#text_id").attr("value");

//或

var text_val=$("#text_id").val();

//获取单选按钮值

var text_radio=$("input[name='textradio']:checked").val();

//获取复选框值

var text_checkbox=$("#text_id").attr("value");

//获取下拉框的值

var text_selectval = $('#text_id').val();

//获取下拉框选中的text

var text_selecttext=$("#text_id").find("option:selected").text(); 

2.对表单的其他处理

//文本框,文本域

$("#text_id").attr("value","");//清空内容

$("#text_id").attr("value","text");//清空内容

//单选按钮

$("input[name='textradio']:checked").attr("checked",'10');//将当前选中的单选按钮value的值设为10

//复选框

$("#text_id").attr("checked,"");//未选中的值

$("#text_id").attr("checked",true);//选中的值

if($("#text_id").attr('checked')==undefined) //判断是否已经选中

//下拉框

$("#text_id").attr("value",'text');//将当前选中的项value的值设为10

$("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#text_id")//添加下拉框的option

$("#text_id").empty();//清空下拉框

 

猜你喜欢

转载自blog.csdn.net/qq_36441761/article/details/80304952