【发布时间】:2026-02-02 02:30:02
【问题描述】:
大家好,我是新来的,也是学习 javascript 的初学者... 我现在有一个问题是从函数 start() 调用函数 当我选择级别和算术运算时,它将以函数 start() 开始 那么这两个变量将被保存... 但问题是无法调用下一个函数 level() 和 operation() 我可以知道是什么问题吗? 是否我对 >> if(levelselect=="1") 以及 if(operationselect=="add") 选择该部分有错误...谢谢帮助我
<script language="javascript">
var levelselect;
var operationselect;
var num1;
var num2;
var data;
var result;
function start(myForm) {
levelselect = myForm["level"].value;
operationselect = myForm["operation"].value;
level();
}
function level() {
if (levelselect == "1") {
num1 = (Math.floor(Math.random() * 9 + 1));
num2 = (Math.floor(Math.random() * 9 + 1));
operation();
} else if (levelselect == "2") {
num1 = (Math.floor(Math.random() * 90 + 10));
num2 = (Math.floor(Math.random() * 90 + 10));
operation();
} else if (levelselect == "3") {
num1 = (Math.floor(Math.random() * 900 + 100));
num2 = (Math.floor(Math.random() * 900 + 100));
operation();
}
}
function operation() {
if (operationselect == "add") {
data = window.prompt(+num1 + " + " + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "sub") {
data = window.prompt(+num1 + " - " + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "div") {
data = window.prompt(+num1 + " / " + num2 + "?", "0");
result = parseInt(data);
check();
} else if (operationselect == "mul") {
data = window.prompt(+num1 + " * " + num2 + "?", "0");
result = parseInt(data);
check();
}
}
</script>
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Assignment 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>body>
<form id="form1" name="form1" method="post" action="" onsubmit="start(this);return false;">
<table align="center">
<tr align="center">
<td>
<label>Choose your Level :</label>
<select id="level">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr align="center">
<br>
<br>
<br>
<td>
<label>Choose your arithmetic operations :</label>
<select id="operation">
<option value="add">Addition</option>
<option value="sub">Subtraction</option>
<option value="div">Division</option>
<option value="mul">Multiplication</option>
</select>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Generate question" />
</td>
</tr>
</table>
</form>
</body>
</html>
【问题讨论】:
标签: javascript