javascript获取单选按钮的值

来源:百度知道 编辑:UC知道 时间:2024/06/11 07:17:43
登录页面定义了一个检查文本域的函数:
<script language="javascript">
function Mycheck(form){
for(i=0;i<form.length;i++){
if(form.elements[i].value==""){
alert(form.elements[i].title + "不能为空!");return false;}
}
}
</script>
现在我想对这个函数进行改进,加了4个单选按钮radiobutton,选定值分别为1-4,如果选定值为1-3就要检查文本域,如果选定值为4就不用检查文本域了!这个函数该怎么该??帮帮满!!!

<html>
<head>
<base href="<%=basePath%>">
<script language="javascript">
function Mycheck(radio){
if(radio.id<4){
if(document.getElementById('data').value.length==0){
alert("文本框内容不能为空!");
}
}
}
</script>
<title>My JSP 'jsp.jsp' starting page</title>
</head>

<body>
<form action="div.jsp">
文本域: <input type="text" id="data">
</form>
<input type="radio" id="1" checked="checked" name="radiobutton" value="radiobutton" onclick="Mycheck(this);">1
<input type="radio" id="2" checked="checked" name="radiobutton" value="radiobutton" onclick="Mycheck(this);"