我想创建一个小调查/调查问卷,询问用户他们是否年龄超过18岁。一旦按下Enter按钮,我想做两个选项。一:如果他们不超过18岁,它将把他们带到另一个网页。还有两个:如果他们超过18岁,它会将他们带到另一个网页。 它让我想起了Java中的“if”“else”语句,但我知道这不是Java。我正在使用HTML(Dreamweaver),我无法弄明白。有人能指出我正确的方向吗?
我已经袒露了它:
<!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>WAIT!</title>
</head>
<body>
<p>WAIT!</p>
<p>Let us know more about you.</p>
<p>Please fill out this form so that we can guide you to YOUR world. </p>
<p> </p>
<p>Are you a:</p>
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>
<p> Age: </p>
<form>
<input type="radio" name="sex" value="male">
younger than 18<br>
<input type="radio" name="sex" value="female">
18+
</form>
<p></p>
<form name="input" action="#" method="get">
<input type="submit" value="Enter">
</form>
</body>
</html>
要查看输出,请复制并粘贴上面的代码并输入here。然后按提交代码。
答案 0 :(得分:1)
这是一个示例脚本,用于重定向用户,使用javascript检查在广播中选择的内容:
<!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>WAIT!</title>
</head>
<script>
function redirect() {
if(document.getElementById("m").checked == true)
{
window.open("http://www.codeforbrowser.com")
}
else {
window.open("http://www.yahoo.com")
}
}
</script>
<body>
<p>WAIT!</p>
<p>Let us know more about you.</p>
<p>Please fill out this form so that we can guide you to YOUR world. </p>
<p> </p>
<p>Are you a:</p>
<form>
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female
</form>
<p> Age: </p>
<form>
<input type="radio" name="sex" value="male" id="m" >
younger than 18<br>
<input type="radio" name="sex" value="female" id="f">
18+
</form>
<p></p>
<form name="input" action="#" method="get">
<input type="submit" value="Enter" onclick="redirect();">
</form>
</body>
</html>
答案 1 :(得分:-1)
给你的表格一些id;
<form id="sex_form">
<input type="radio" name="sex" value="male">
younger than 18<br>
<input type="radio" name="sex" value="female">
18+
</form>
<input type="submit" onclick="validate()" value="Enter">
<script type="text/javascript">
function validate(){
var form = document.getElementById('sex_form');
if(form.firstElementChild.checked){
alert('to younger');
//window.open('younger');
}
else if(form.firstElementChild.nextElementSibling.nextElementSibling.checked){
//window.open('older');
alert('to 18+');
}
else
alert('none selected');
}
</script>