选中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>

Webhosting24:$1.48/月起,日本东京NTT直连/AMD Ryzen 高性能VPS/美国洛杉矶5950X平台大流量VPS/1Gbps端口/

Webhosting24宣布自7月1日起开始对日本机房的VPS进行NVMe和流量大升级,几乎是翻倍了硬盘和流量,价格依旧不变。目前来看,日本VPS国内过去走的是NTT直连,服务器托管机房应该是CDN77*(也就是datapacket.com),加上高性能平台(AMD Ryzen 9 3900X+NVMe),还是有相当大的性价比的。此外在6月30日,又新增了洛杉矶机房,CPU为AMD Ryzen 9...

Tudcloud(月付7.2美元),香港VPS,可选大带宽或不限流量

Tudcloud是一家新开的主机商,提供VPS和独立服务器租用,数据中心在中国香港(VPS和独立服务器)和美国洛杉矶(独立服务器),商家VPS基于KVM架构,开设在香港机房,可以选择限制流量大带宽或者限制带宽不限流量套餐。目前提供8折优惠码,优惠后最低每月7.2美元起。虽然主机商网站为英文界面,但是支付方式仅支付宝和Stripe,可能是国人商家。下面列出部分VPS主机套餐配置信息。CPU:1cor...

数脉科技:香港服务器低至350元/月;阿里云CN2+BGP线路,带宽10M30M50M100M

数脉科技(shuhost)8月促销:香港独立服务器,自营BGP、CN2+BGP、阿里云线路,新客立减400港币/月,老用户按照优惠码减免!香港服务器带宽可选10Mbps、30Mbps、50Mbps、100Mbps带宽,支持中文本Windows、Linux等系统。数脉香港特价阿里云10MbpsCN2,e3-1230v2,16G内存,1T HDD 或 240G SSD,10Mbps带宽,IPv41个,...

checkbox选中为你推荐
投标人chrome三星itunes支持ipad支持ipadgetIntjava支持ipad支持ipad支持ipadCTioswin10关闭445端口win10怎么关闭445的最新相关信息
美国网站空间 备案域名查询 vps动态ip 广东vps edgecast 56折 全能主机 促正网秒杀 php空间申请 福建铁通 银盘服务是什么 1元域名 徐州电信 阿里云邮箱申请 网站防护 小夜博客 新网dns accountsuspended sonya alexa世界排名 更多