【发布时间】:2024-01-02 22:55:01
【问题描述】:
这是我将用于测验的代码。 代码有什么问题?
鼠标悬停(按钮)时,html会提示函数的描述,点击按钮会运行指定的函数。然后,它会提醒用户操作的答案。
<script type="text/javascript">
function a(){
alert('Adds the two numbers.');}
function b(){
alert('Subtracts the second number from the first number.');}
function c(){
alert('Multiplies the two numbers.');}
function d(){
alert('Divides the second number from the first number.');}
function add(){
var ans = form.none.value + form.notwo.value;
alert(form.none.value + '+' +form.notwo.value + '=' + ans);
}
function subtract(){
var ans = form.notwo.value - form.none.value;
alert(form.notwo.value + '-' form.none.value+ '=' + ans);
}
function times(){
var ans = form.none.value * form.notwo.value;
alert(form.none.value + '*' +form.notwo.value + '=' + ans);
}
function over(){
var ans = form.notwo.value / form.none.value;
alert(form.notwo.value + '/' form.none.value+ '=' + ans);
}
</script>
<style>
h1{font-color: red;}
body{ background-color: aquamarine;}
</style>
<!DOCTYPE html>
<html>
<head><title> JAVAcalc </title></head>
<body>
<h1> The Java Calculator </h1>
<form name="me">
Enter all of the textfields required and click the button to use an operation.<br>
First number: <input type = "textbox" name="none" id="none"value="0">
Second number: <input type = "textbox" name="notwo" id="none" value="0"><br>
<input type = "button" name="none" value="Add!" onclick="add()" onmouseover="a()">
<input type = "button" name="none" value="Subtract!" onclick="subtract()" onmouseover="b()">
<input type = "button" name="none" value="Multiply!" onclick="times()" onmouseover="c()">
<input type = "button" name="none" value="Divide!" onclick="over()" onmouseover="d()">
</body>
</html>
提前致谢!祝你有美好的一天!
【问题讨论】:
-
我投票决定将此问题作为离题结束,因为 Stack Overflow 不是“为我编写代码”网站。
-
"您能否插入其他三角函数按钮(例如 sin、cos、tan)?" 是的 "还有什么代码有问题吗?” 有什么问题吗?仅供参考:JavaScript 不是 Java
-
首先,代码永远不会运行。 =(
标签: javascript calculator