嘿,所以我有一个学校的项目,我必须创建一个网站,在网站上必须有一个测验。这些问题要求以数字作为答案,所以我不能使用单选按钮。我知道如何制作文本框和提交按钮,但我认为框不能获取信息,所以我想知道是否有人可以帮助我修复代码
这是我所拥有的一切的结束
*这不是我要问的问题这只是为了让代码正常工作
<P><INPUT TYPE=SUBMIT VALUE="Submit"> </FORM>
<SCRIPT type=text/javascript>
</FORM>function getAnswer(input) { if (input == "3.14") {alert ("Congradulations")} else {alert ("No that's incorrect, please try again...")}
}
</SCRIPT>发布于 2011-02-28 06:39:40
你肯定没有给我们提供回答你的问题所需的完整代码,但这里是我在你的代码片段中看到的所有错误的东西。
最明显的错误是放在<script>标记内的文本</FORM>。
我还修复了你的拼写错误的Congradulations,因为我想这不会太好:)
<p><input type="submit" value="Submit" /></p>
</form>
<script type="text/javascript">
function getAnswer(input) {
if (input == "3.14") { //What is the value of Pi to 2 decimal places?
alert("Congratulations");
} else {
alert("No that's incorrect, please try again...");
}
}
</script>如果这对我们没有帮助,请向我们展示更多您的文件。
发布于 2012-03-05 20:14:38
@Olivia试试这段代码
<!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>Untitled Document</title><br />
</head>
<body>
<form id="form1" name="form1" method="post" action="" onsubmit="getAnswer();"
<p>
<label for="textfield"></label>
Q. What is the value of Pi to 2 decimal places?</p>
<p>Answer
<input type="text" name="textfield1" id="textfield1" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
<script type="text/javascript">
function getAnswer(input) {
if (document.form1.textfield1.value == "3.14") { //What is the value of Pi to 2 decimal places?
alert("Congratulations");
} else {
alert("No that's incorrect, please try again...");
}
}
</script>
</body>
</html>在表单提交中,我给出了一个调用函数的操作。
onsubmit="getAnswer();"在函数内部,我得到的值是
document.form1.textfield1.value 然后是简单的步骤。干杯
https://stackoverflow.com/questions/5136498
复制相似问题