问题说明:请照我下面的JSP网页代码,详细写一个能够判断单选按钮有没有选中任何一个的javascript,可以插在我的网页代码的头部。我要一开始所有单选按钮都没有选中,要求录入者来从四个中任选其中一个,如果录入者没有选中任何一个,在提交表单的时候会弹出对话框提示。各位大哥大姐,懂这个的,有劳了,不会少给分你的!谢谢!下面是我的网页代码:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>成绩录入</title>
</head><body>
<form id="form1" name="form1" method="post" action="add_cj.jsp">
<table width="416" height="162" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="115" align="center">音乐</td>
<td width="294"><input type="radio" name="yingye" value="radiobutton" />
优
<input type="radio" name="yingye" value="radiobutton" />
良
<input type="radio" name="yingye" value="radiobutton" />
及格
<input type="radio" name="yingye" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td align="center">美术</td>
<td><input type="radio" name="meisu" value="radiobutton" />
优
<input type="radio" name="meisu" value="radiobutton" />
良
<input type="radio" name="meisu" value="radiobutton" />
及格
<input type="radio" name="meisu" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td align="center">自然科学</td>
<td><input type="radio" name="zirankexue" value="radiobutton" />
优
<input type="radio" name="zirankexue" value="radiobutton" />
良
<input type="radio" name="zirankexue" value="radiobutton" />
及格
<input type="radio" name="zirankexue" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="tijiao" type="submit" id="tijiao" value="提交" />
<input name="chongxie" type="reset" id="chongxie" value="重写" /></td>
</tr>
</table>
</form>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>成绩录入</title>
</head><body>
<form id="form1" name="form1" method="post" action="add_cj.jsp">
<table width="416" height="162" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="115" align="center">音乐</td>
<td width="294"><input type="radio" name="yingye" value="radiobutton" />
优
<input type="radio" name="yingye" value="radiobutton" />
良
<input type="radio" name="yingye" value="radiobutton" />
及格
<input type="radio" name="yingye" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td align="center">美术</td>
<td><input type="radio" name="meisu" value="radiobutton" />
优
<input type="radio" name="meisu" value="radiobutton" />
良
<input type="radio" name="meisu" value="radiobutton" />
及格
<input type="radio" name="meisu" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td align="center">自然科学</td>
<td><input type="radio" name="zirankexue" value="radiobutton" />
优
<input type="radio" name="zirankexue" value="radiobutton" />
良
<input type="radio" name="zirankexue" value="radiobutton" />
及格
<input type="radio" name="zirankexue" value="radiobutton" />
不及格</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="tijiao" type="submit" id="tijiao" value="提交" />
<input name="chongxie" type="reset" id="chongxie" value="重写" /></td>
</tr>
</table>
</form>
</body>
</html>
解决方案 »
- 开发工具和环境咨询
- Hibernate为什么不接收我给他的Set集合
- jsp国际化问题指教!!
- MYeclipse最新版下载
- JSP十大问题请指教
- JAVA 如何获取手机的MAC地址啊
- 怎样获得对方机的绝对路径呢?/
- 请教:如何在jsp页面中插入.htm文件。在线等
- 大家帮忙看一下这一个连接数据库的代码有什么错的地方!
- Docker化的SpringBoot应用,无法连接数据库
- 高手来啊 图片上传问题
- Error creating bean with name 'userManage' defined in class path resource [applicationContext.xml]: Cannot resolve reference to
function check()
{
var frm = document.forms[0];
var value = 0;
for (var i = 0; i < frm.a.length; i ++)
{
if (frm.a[i].checked)
value = frm.a[i].value;
}
if (value == 0)
alert('没有被选中的');
else
alert(value + '被选中了');
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>成绩录入 </title>
<script>
function checkInput(){
var yingyue = document.getElementsByName("yingye");
var value1 = 0;
for(var i=0;i<yingyue.length;i++){
if(yingyue[i].checked)
{
value1 = yingyue[i].value;
break;
}
}
if(value1 == 0){
alert("please choose ur score of yingyue");
return false;
}
}
</script>
</head> <body>
<form id="form1" name="form1" method="post" action="add_cj.jsp">
<table width="416" height="162" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="115" align="center">音乐 </td>
<td width="294"> <input type="radio" name="yingye" value="4" />
优
<input type="radio" name="yingye" value="3" />
良
<input type="radio" name="yingye" value="2" />
及格
<input type="radio" name="yingye" value="1" />
不及格 </td>
</tr>
<tr>
<td align="center">美术 </td>
<td> <input type="radio" name="meisu" value="4" />
优
<input type="radio" name="meisu" value="3" />
良
<input type="radio" name="meisu" value="2" />
及格
<input type="radio" name="meisu" value="1" />
不及格 </td>
</tr>
<tr>
<td align="center">自然科学 </td>
<td> <input type="radio" name="zirankexue" value="4" />
优
<input type="radio" name="zirankexue" value="3" />
良
<input type="radio" name="zirankexue" value="2" />
及格
<input type="radio" name="zirankexue" value="1" />
不及格 </td>
</tr>
<tr>
<td colspan="2" align="center"> <input name="tijiao" type="submit" id="tijiao" value="提交" onClick="return checkInput();"/>
<input name="chongxie" type="reset" id="chongxie" value="重写" /> </td>
</tr>
</table>
</form>
</body>
</html>
这样在后台就可以 String yingyue = request.getParameter("yingye");