主题 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>
轻云互联成立于2018年的国人商家,广州轻云互联网络科技有限公司旗下品牌,主要从事VPS、虚拟主机等云计算产品业务,适合建站、新手上车的值得选择,香港三网直连(电信CN2GIA联通移动CN2直连);美国圣何塞(回程三网CN2GIA)线路,所有产品均采用KVM虚拟技术架构,高效售后保障,稳定多年,高性能可用,网络优质,为您的业务保驾护航。活动规则:用户购买任意全区域云服务器月付以上享受免费更换IP服...
Budgetvm(原EZ机房),2005年成立的美国老品牌机房,主打美国4个机房(洛杉矶、芝加哥、达拉斯、迈阿密)和日本东京机房的独立服务器和VPS业务,而且不限制流量,默认提供免费的1800G DDoS防御服务,支持IPv6和IPMI,多种免费中文操作系统可供选择,独立服务器主打大硬盘,多硬盘,大内存,用户可以在后台自行安装系统等管理操作!内存可定制升级到1536G,多块硬盘随时加,14TBSA...
搬瓦工和Vultr哪个好?搬瓦工和Vultr都是非常火爆的国外VPS,可以说是国内网友买的最多的两家,那么搬瓦工和Vultr哪个好?如果要选择VPS,首先我们要考虑成本、服务器质量以及产品的售后服务。老玩家都知道目前在国内最受欢迎的国外VPS服务商vultr和搬瓦工口碑都很不错。搬瓦工和Vultr哪个稳定?搬瓦工和Vultr哪个速度快?为了回答这些问题,本文从线路、速度、功能、售后等多方面对比这两...