enter link description here enter code here
我的问题是,一旦选中,单选按钮就不会取消选择。这个表单连接到我为我的作业构建的php文件。在Dreamweaver中,如果我保留name属性的默认值,我没有按钮的问题,但由于name属性的值必须与php文件中的name属性匹配,因此我无法保留默认名称。我尝试过使用组按钮和单个按钮并复制它们。在文本页面中,我可以在选择另一个按钮时取消选择按钮。然后它停止工作,所有按钮都保持检查状态。我很困惑,因为我认为单选按钮包含布尔值,当选择一个时,另一个被取消选择。有什么建议?这是代码
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Homework 7</title>
<script type="text/javascript">
function edits()
{
if(document.getElementById("name").value=="")
{
alert("Please enter your whole name.")
return false;
}
if(document.getElementById("jarreau").checked=="")
{
alert("Please enter your whole name.")
return false;
}
else if(document.getElementById("aretha").checked=="")
{
alert("Please enter your whole name.")
return false;
}
else if(document.getElementById("withers").checked=="")
{
alert("Please enter your whole name.")
return false;
}
else if(document.getElementById("joel").checked=="")
{
alert("Please enter your whole name.")
return false;
}
else if(document.getElementById("warwidk").checked=="")
{
alert("Please enter your whole name.")
return false;
}
if(document.getElementById("rate").value=="")
{
alert("Please enter your whole name.")
return false;
if(document.getElementById("email").value=="")
{
alert("Please enter your whole name.")
return false;
}
}
else return true;
}
</script>
<style type="text/css">
body {
background-color: #F9F;
}
h1 {
font-size: xx-large;
color: #FFF;
}
</style>
</head>
<body>
<h1 font color="#fff">Old School Concert</h1>
<table width="87%" border="0" cellspacing="0" cellpadding="2">
<tr>
<th align="left" width="19%" scope="col">Al Jarreau</th>
<th align="left"width="13%" scope="col">Aretha Franklin</th>
<th align="left"width="16%" scope="col">Bill Withers</th>
<th align="left"width="19%" scope="col">Billy Joel</th>
<th align="left"width="19%" scope="col">Dionne Warwick</th>
</tr>
<tr>
<td><img src="al jarreau.jpg" width="247" height="204" alt="Al Jarreau" /></td>
<td><img src="images/aretha franklin.jpg" width="198" height="204" alt="aretha franklin" /></td>
<td><img src="Bill Withers.jpg" width="192" height="204" alt="Bill Withers" /></td>
<td><img src="billy joel.jpg" width="225" height="204" alt="Billy Joel" /></td>
<td><img src="Dionne Warwick.jpg" width="176" height="204" alt="Dionne Warwick" /></td>
</tr>
<form name="service" method="post" action="concert.php" />
<label for="fname">First name:</label>
<input name="name" type="text" id="fname" size="20" maxlength="15" />
(optional)
<br />
<label for="lname">Last name:</label>
<input name="name" type="text" id="lname" size="20" maxlength="15" />
(optional)<br />
<label>Which performance you liked best:</label><br />
<p>
<label>
<input type="radio" name="jarreau" value="radio" id="RadioGroup1_0"/>
Al Jarreau</label>
<br />
<label>
<input type="radio" name="aretha" value="radio" id="RadioGroup1_1" />
Aretha Franklin</label>
<br />
<label>
<input type="radio" name="withers" value="radio" id="RadioGroup1_2" />
Bill Withers</label>
<br />
<label>
<input type="radio" name="joel" value="radio" id="RadioGroup1_3" />
Billy Joel</label>
<br />
<label>
<input type="radio" name="warwick" value="radio" id="RadioGroup1_4" />
Dionne Warwick</label>
</p>
<br />
<label for="rate">On a scale of 1 to 10 how would you rate this concert?</label>
<br />
<input name="rate" type="text" id="rate" size="5" maxlength="2" />
<label for="email"><br />
Your email address:</label>
<br />
<input name="email" type="text" id="email" size="45" maxlength="45" />
</p>
<p>
<label for="comment">Your comments:</label>
<textarea name="comment" cols="50" rows="5" id="comment"></textarea>
</p>
<input type="button" value="submit" name="" id="" onclick="edits()" />
</form>
</body>
</html>
答案 0 :(得分:1)
你必须给所有的单选按钮相同&#34; name&#34;像:
<input name="thesamegroup" type="button" value="submit" id="" onclick="edits()" />
<input name="thesamegroup" type="text" id="email" size="45" maxlength="45" />