我有一个数组,但无法在提交时显示在同一页面上。表单应该如何工作,显示旁边选择的内容。如果它没有填充它,它表明需要放入一些东西。我做错了什么,所以数组不会显示在同一页面上?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Ex 2</title>
<link href="styles.css" rel="stylesheet">
<script>
function checkForm(){
var chk = true;
var mName = document.getElementById("txtM");
var meth = document.getElementById("methM");
var rad = document.getElementById("radM");
var sel = document.getElementById("selM");
var heal = document.getElementById("a");
var dark = document.getElementById("b");
var ele = document.getElementById("c");
var wep = document.getElementById("imp");
var last = document.getElementById("final");
var randomnumber=Math.floor(Math.random()*5);
var quotes = new Array()
quotes[0] = "You Are A Warrior"
quotes[1] = "You Are A Mesmer"
quotes[2] = "You Are A Elementalist"
quotes[3] = "You Are A Necromancer"
quotes[4] = "You Are A Guardian"
document.write(quotes[randomnumber]);
meth.setAttribute("style", "display:none");
rad.setAttribute("style", "display:none");
sel.setAttribute("style", "display:none");
if (mName.value=='no'){
document.getElementById("methM").innerHTML = "No";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (mName.value=='yes'){
document.getElementById("methM").innerHTML = "Yes";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (mName.value==''){
document.getElementById("methM").innerHTML = "So You Don't Like To Do Any Damage?";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (heal.checked) {
document.getElementById("radM").innerHTML = "Healer";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (dark.checked) {
document.getElementById("radM").innerHTML = "Dark";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (ele.checked) {
document.getElementById("radM").innerHTML = "One with the Elements";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==1){
document.getElementById("selM").innerHTML = "Rifle";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==2){
document.getElementById("selM").innerHTML = "Bow and Arrow";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==3){
document.getElementById("selM").innerHTML = "Daggers";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==0){
document.getElementById("selM").innerHTML = "Gotta Have A Weapon!";
sel.setAttribute("style", "display:inline");
chk = false;
}
}
</script>
</head>
<body>
<div class="page">
<main role="main">
<article>
<div id="errMess" class="errMess"></div>
<h1>What Guild Wars 2 Profession Are You</h1>
<div class="cssTable" style="margin-top:-25px;">
<form method="post">
<table>
<tr><td colspan="3"></td></tr>
<tr>
<td><div align="right">Do you like to do high damage?</div></td><td width="217">
<input id="txtM" name="txtM" type="text" size="25"></td><td ><div id="methM" style="display:none"></div></td></tr>
<tr>
<td><div align="right">What best describes you?</div></td><td>
<input id="a" type="radio" name = "group1" value="A">Healer</input>
<input id="b" type="radio" name = "group1" value="B">Dark</input>
<input id="c" type="radio" name = "group1" value="C">Earthling</input>
</td><td><div id="radM" style="display:none"></div></td>
</tr>
<tr>
<td>What weapon would you like to have?</td>
<td>
<select id="imp"><option value="0" selected="true">Select One</option>
<option value="1">Rifle</option>
<option value="2">Bow and Arrow</option>
<option value="3">Daggers</option></select>
</td><td><div id="selM" style="display:none"></div></td>
</tr>
<tr><td colspan="3" align="right"><input type="button" class="styled-button-7" value="Send" onclick="checkForm()"/></td></tr></table></form></div></article>
</main></div>
</body>
</html>
答案 0 :(得分:0)
您需要在chk
回调中返回checkForm()
来完成这项工作。
return chk;