现在做一个调查问卷,从后台循环取出radio单选问题,怎么验证这些radio必须选择,如果不选择提示哪个没有选中,我现在用jquery怎么实现呢,因为对jquery不熟悉,所以希望大家可以帮忙,谢谢
解决方案 »
- 邮件群发、以及C#版的在线聊天
- treeview iframe 问题
- 去掉ie6,ie7图片连接蓝色框?????
- 怎么把Excel显示到Web页面上,老问题了,还是没有解决?
- 读textBox值乱码问题,找了三天三夜的资料,都没解决,请高手们帮帮忙?在线等!
- 我要将我的.net版本换成2003版的,我需要注意些什么事情??
- 三元表达式。。。。########################### 100%结贴
- 帮忙看下,在aspx使用response.write的错误
- js 没反应 求大神帮忙!!!!
- 我想隐藏 DataGrid 中的某一列,该怎么办???
- asp的页面求翻译成.net的,主要功能就是实现流量统计。
- 二级联动赋值问题
if($(this).attr("checked"))
{
//这里是被选中的
}
});
in the example, if you not choice the sex field, when you click the submit button, will appear the alert info and the sex field will add the red border.
the code below is: <div>
<span>UserName</span>
<div><input type="text" id="username" /></div>
</div>
<div>
<fieldset>
<legend>Sex:</legend>
<input type="radio" name="sex" value="0" id="man" /><label for="man">Man</label>
<input type="radio" name="sex" value="1" id="women" /><label for="women">Women</label>
</fieldset>
</div>
<div>
<input type="button" value="Submit" id="Submit" />
</div> <script type="text/javascript" src="JS/jquery-1.4.4.js"></script>
<script type="text/javascript">
var sex = "";
$(function() {
$("input#Submit").click(function() {
sex = "";
sex = $("input[type='radio'][name='sex']:checked").val();
if (sex == "" || sex==null) {
alert("you should choice the sex!");
$("fieldset").parent().css({ "border": "solid 1px red" });
}
});
});
</script>just a example. the more functions, which you can add.
比如
<input type="radio" name="radio1" value="0" id="man" />Man
<input type="radio" name="radio1" value="1" id="women" />Women<input type="radio" name="radio2" value="0" id="man" />Man
<input type="radio" name="radio2" value="1" id="women" />Women<input type="radio" name="radio3" value="0" id="man" />Man
<input type="radio" name="radio3" value="1" id="women" />Women.
.
.
<input type="radio" name="radio10" value="0" id="man" />Man
<input type="radio" name="radio10" value="1" id="women" />Women是不是要写10次验证啊
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#vali").click(function(){
$("input[type='radio']").each(function(){
if(!$(this).attr("checked")){
alert($(this).next().html()+"为必选项,请选择");
}
})
})
})
</script>
</head>
<body>
<input type="radio" name="radio1" value="0" id="man" /><span>男人</span>
<input type="radio" name="radio1" value="1" id="women" /><span>女人</span>
<input type="radio" name="radio1" value="2" id="nopeople" /><span>非男人非女人</span>
<a href="#" id="vali">验证</a>
</body>
</html>