选中jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

checkbox选中  时间:2021-04-22  阅读:()

主题 jquery radio取值 checkbox取值 select取值 radio选中 checkbox选中 select选中

内容部分

jquery取radio单选按钮

// var strMess = ' <%=Exchange() %>' ;

// if (strMess == "兑换成功") {

// $("#btnSure") . show() ; //显示提交按钮

// }

// else if (strMess. length > 0) {

// alert(strMess) ; return false;

// }jquery取radio单选按钮的值

$("input[name=' items' ] :checked") .val () ;jquery radio取值 checkbox取值 select取值 radio选中 checkbox选中select选中及其相关

获取一组radio被选中项的值var item = $(' input[name=items] [checked] ' ) .val () ;

获取select被选中项的文本var item = $("select[name=items] option[selected]") . text() ;select下拉框的第二个元素为当前选中值

$('#select_id' ) [0] . selectedIndex = 1 ;radio单选组的第二个元素为当前选中值

$(' input[name=items] ' ) .get(1) .checked = true;

获取值

文本框文本区域 $("#txt") .attr("value") 

多选框checkbox $("#checkbox_id") .attr("value") 

单选组radio $("input[type=radio] [checked]") .val () ;

下拉框select $('#sel' ) .val () ;

控制表单元素

文本框文本区域 $("#txt") .attr("value", ' ' ) ;//清空内容

$("#txt") .attr("value", ' 11' ) ;//填充内容

多选框checkbox $("#chk1") .attr("checked", ' ' ) ;//不打勾

$("#chk2") .attr("checked", true) ;//打勾if($("#chk1") .attr('checked' )==undefined) //判断是否已经打勾

单选组radio $("input[type=radio]") .attr("checked", '2' ) ;//设置value=2的项目为当前选中项

下拉框select $("#sel") .attr("value", '-sel3' ) ;//设置value=-sel3的项目为当前选中项

$("<option value=' 1' >1111</option><optionvalue='2' >2222</option>") .appendTo("#sel")//添加下拉框的option$("#sel") . empty()  //清空下拉框

刚开始接触jquery很多东西不熟悉

在用$("#id")来获得页面的input元素的时候发现$("#id") .value不能取到值

<script type="text/javascript">function add()

{if ($("#TextBox1") .val () == "")

{alert("输入的名称不能为空!") ;

$("#TextBox1") .focus() ;return false;

}if ($("#TextBox2") .val () == "")

{alert("年龄不能为空!") ;

$("#TextBox2") .focus() ;return false;

}if ($("#TextBox2") .val () != "") //年龄

{var intvar =/^\d+$/;if ( ! intvar. test($("#TextBox2") .val () ) )

{alert("年龄格式不正确请输入2位数字!") ;

$("#TextBox2") .focus() ;return false;

}

}if ($("#TextBox3") .val () == "")

{alert("毕业学校不能为空!") ;

$("#TextBox3") .focus() ;

return false;

}if ($("#TextBoxjy") .val () == "") //工作经验

{alert("工作经验不能为空!") ;

$("#TextBoxjy") .focus() ;return false;

}if ($("#TextBoxjy") .val () != "") //工作经验

{var intvar2 = /^\d+$/;if ( ! intvar2. test($("#TextBoxjy") .val () ) ) {alert("格式不正确请输入2位数字!") ;

$("#TextBoxjy") .focus() ;return false;

}

}var sex = $("input[name=' sex' ] :checked") .val () ;var job = $("input[name=' job' ] :checked") .val () ;if (sex == undefined)

{alert("没有选择性别 ") ;return false;

}if (job == undefined)

{alert("全/兼职没选中") ;return false;

}if ($("#TextBox5") .val () == "") //电话

{alert("电话不能为空!") ;

$("#TextBox5") .focus() ;return false;

}if ($("#TextBox5") .val () != "") {var isMobile = /^ (?: 13\d| 15\d)\d{5} (\d{3} |\*{3} )$/;var isPhone = /^ ( (0\d{2,3} )-)?(\d{7,8} ) (-(\d{3, } ) )?$/;if ( ! isMobile. test($("#TextBox5") .val () )

&& ! isPhone. test($("#TextBox5") .val () ) )

{alert("请正确填写手机号或电话号格式不正确") ;

$("#TextBox5") .focus() ;return false;

}

}if ($("#FreeTextBox1") .val ()== "")

{alert("工作经验不能为空") ;

$("#FreeTextBox1") .focus() ;return false;

}var TextBox1 = escape($("#TextBox1") .val () ) ;var TextBox2 = escape($("#TextBox2") .val () ) ;var TextBox3 = escape($("#TextBox3") .val () ) ;var TextBox5 = escape($("#TextBox5") .val () ) ;var rad1 =escape(sex) ;var rad2 = escape(job) ;var TextBoxjy =escape($("#TextBoxjy") .val () ) ;var FreeTextBox1=escape($("#FreeTextBox1") .val () ) ;var Label2 = escape($("#Label2") . text() ) ;var Label4 = escape($("#Label4") . text() ) ;

$.ajax( {type: "POST",url: "add.aspx",data:"Label2="+Label2+"&Label4="+Label4+"&TextBox1="+ TextBox1 + "&TextBox2=" + TextBox2 + "&TextBox3=" +

TextBox3+"&TextBox5="+TextBox5+"&rad1="+rad1+"&rad2="+rad2+"&TextBoxjy="+TextBoxjy+"&FreeTextBox1="+FreeTextBox1,success: function(msg)

{if (msg == "ok")

{alert("数据提交成功!") ;window. location.href = 'JobList.aspx' ;

}else

{alert("数据提交失败!") ;

}

}

} ) ;

}

</script>

<asp:Label ID="Label1"runat="server"></asp:Label>

<asp:Label ID="msg" runat="server"Visible="false"></asp:Label>

<asp:Label ID="Label2"runat="server"></asp:Label>

<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>

<input type="Radio" name="job"value="全职" id="RadioButton3" runat="server"/>

<input type="Radio" name="job"value="兼职" id="RadioButton4"runat="server"/>

=

<input id="Submit1" type="button" value="提交简历" onclick="return add()" style="height:35px"/>

后来终于在伟大的百度帮助下找到了问题的原因

$("")是一个jquery对象而不是一个dom elementvalue是dom element的属性jquery与之对应的是valval () :获得第一个匹配元素的当前值。val (val) :设置每一个匹配元素的值。

所以代码应该这样写

取值 val = $("#id") [0] .value;

赋值

$("#id") [0] .value = "new value";

或者$("#id") .val ("new value") ;

或者这样也可以 val = $("#id") .attr("value") ;

function add()

{var Label2 = $("#Label2") . text() ;var Label4 = $("#Label4") . text() ;alert(Label2) ;if (Label2 == ""&& Label4 == "")

{if ($("#TextBox1") .val () == "")

{alert("输入的名称不能为空!") ;

$("#TextBox1") .focus() ;return false;

}if ($("#TextBox2") .val () == "")

{alert("年龄不能为空!") ;

$("#TextBox2") .focus() ;return false;

}if ($("#TextBox2") .val () != "") //年龄{var intvar =/^\d+$/;if ( ! intvar. test($("#TextBox2") .val () ) ){alert("年龄格式不正确请输入2位数字!") ;$("#TextBox2") .focus() ;return false;

}

}if ($("#TextBox3") .val () == "")

{alert("毕业学校不能为空!") ;

$("#TextBox3") .focus() ;return false;

}if ($("#TextBoxjy") .val () == "") //工作经验{alert("工作经验不能为空!") ;

$("#TextBoxjy") .focus() ;return false;

}if ($("#TextBoxjy") .val () != "") //工作经验{var intvar2 = /^\d+$/;

if ( ! intvar2. test($("#TextBoxjy") .val () ) ) {alert("格式不正确请输入2位数字!") ;

$("#TextBoxjy") .focus() ;return false;

}

}

// var RadioButton1 =

$(' input:radio[name="RadioButton1"] :checked' ) .val () ; //性别

// var RadioButton2 =

$(' input:radio[name="RadioButton2"] :checked' ) .val () ; //性别

// if (RadioButton1 == null | | RadioButton2==null)// {

// alert("性别没选中!") ;

// // $("#TextBoxjy") .focus() ;

// return false;

// }

// var RadioButton3 =

$(' input:radio[name="RadioButton3"] :checked' ) .val () ; //性别

// var RadioButton4 =

$(' input:radio[name="RadioButton4"] :checked' ) .val () ; //性别

// if (RadioButton3 == null | | RadioButton4==null)// {

// alert("全/兼职没选中!") ;

// // $("#TextBoxjy") .focus() ;

// return false;

// }

// if ($("#TextBox5") .val () == "") //电话

// {

// alert("电话不能为空!") ;

// $("#TextBox5") .focus() ;

// return false;

// }

// if ($("#TextBox5") .val () != "") {

// var isMobile = /^ (?: 13\d| 15\d)\d{5} (\d{3} |\*{3} )$/;// var isPhone =

/^ ( (0\d{2,3} )-)?(\d{7,8} ) (-(\d{3, } ) )?$/;

// if ( ! isMobile. test($("#TextBox5") .val () )

&& ! isPhone. test($("#TextBox5") .val () ) )

// {

// alert("请正确填写手机号或电话号格式不正确") ;// $("#TextBox5") .focus() ;

// return false;

// }

// }

// if ($("#FreeTextBox1") .val () != "")

// {

// alert("工作经验不能为空") ;

// $("#FreeTextBox1") .focus() ;

// return false;

// }

// var TextBox1 = escape($("#TextBox1") .val () ) ;

// var TextBox2 = escape($("#TextBox2") .val () ) ;

// var TextBox3 = escape($("#TextBox3") .val () ) ;

// var TextBox5 = escape($("#TextBox5") .val () ) ;

// var rad1 =escape(RadioButton1) ;

// var rad2 =escape(RadioButton2) ;

// var rad3 =escape(RadioButton3) ;

// var rad4 =escape(RadioButton4) ;

// var TextBoxjy =escape($("#TextBoxjy") .val () ) ;

// var FreeTextBox1=escape($("#FreeTextBox1") .val () ) ;// var Label2 = escape($("#Label2") . text() ) ;

// var Label4 = escape($("#Label4") . text() ) ;

// if(rad1 !=null&&rad3!=null)

// {

// $.ajax( {

// type: "POST",

// url: "Control/WebUserControl.ascx",

// data:"Label2="+Label2+"&Label4="+Label4+"&TextBox1=" + TextBox1 + "&TextBox2=" + TextBox2 + "&TextBox3=" +

TextBox3+"&TextBox5="+TextBox5+"&rad1="+rad1+"&rad3="+rad3+"&TextBoxjy="+TextBoxjy+"&FreeTextBox1="+FreeTextBox1+",

// success: function(msg)

// {

// if (msg == "cf")

// {

// alert("请换个姓名!") ;

// }

// if (msg == "ok")

// {

// alert("数据提交成功!") ;

// window. location.href = 'JobList.aspx' ;// }

// else

// {

// alert("数据提交失败!") ;

// }

// }

// } ) ;

// }//

}

</script>

无视CC攻击CDN ,DDOS打不死高防CDN,免备案CDN,月付58元起

快快CDN主营业务为海外服务器无须备案,高防CDN,防劫持CDN,香港服务器,美国服务器,加速CDN,是一家综合性的主机服务商。美国高防服务器,1800DDOS防御,单机1800G DDOS防御,大陆直链 cn2线路,线路友好。快快CDN全球安全防护平台是一款集 DDOS 清洗、CC 指纹识别、WAF 防护为一体的外加全球加速的超强安全加速网络,为您的各类型业务保驾护航加速前进!价格都非常给力,需...

DogYun春节优惠:动态云7折,经典云8折,独立服务器月省100元,充100送10元

传统农历新年将至,国人主机商DogYun(狗云)发来了虎年春节优惠活动,1月31日-2月6日活动期间使用优惠码新开动态云7折,经典云8折,新开独立服务器可立减100元/月;使用优惠码新开香港独立服务器优惠100元,并次月免费;活动期间单笔充值每满100元赠送10元,还可以参与幸运大转盘每日抽取5折码,流量,余额等奖品;商家限量推出一款年付特价套餐,共100台,每个用户限1台,香港VPS年付199元...

CloudCone月付$48,MC机房可小时付费

CloudCone商家在前面的文章中也有多次介绍,他们家的VPS主机还是蛮有特点的,和我们熟悉的DO、Linode、VuLTR商家很相似可以采用小时时间计费,如果我们不满意且不需要可以删除机器,这样就不扣费,如果希望用的时候再开通。唯独比较吐槽的就是他们家的产品太过于单一,一来是只有云服务器,而且是机房就唯一的MC机房。CloudCone 这次四周年促销活动期间,商家有新增独立服务器业务。同样的C...

checkbox选中为你推荐
重要产品信息指南支持ipadtracerouteLinux 下traceroute的工作原理是什么 !x-routerx-0.4x等于多少?fusionchartsfusioncharts怎么生成图片至exceliphonewifi苹果手机怎么wi-fi共享google中国地图谷歌中国地图用的是什么投影,什么坐标系win7关闭135端口win7系统怎么关闭135端口?网上很多方法都不好用!altools.u32labview中有个叫RGB(U32)的是神马?怎么弄出来?winrar5.0安装了winrar5.0,但是打不开rar文件
cn域名备案 万网免费域名 域名抢注工具 awardspace 鲨鱼机 网站被封 免费ftp空间申请 微信收钱 免费防火墙 佛山高防服务器 免费高速空间 dnspod 中国联通宽带测速 国内空间 云销售系统 privatetracker 镇江高防服务器 架设代理服务器 windowsserver2012 美国西雅图独立 更多