求助:怎样通过一个按钮来显示每一步的结果?
以下的按钮点击无效,不知问题出在哪了
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>help</title> <script type="text/javascript"> function add2(x,y){ {var sum,x,y; sum = x+y; return sum; } var result1,result2,sumall; result1=add2(3,4); result2=add2(5,6); sumall=result1+result2; document.write(result1); document.write(result2); document.write(sumall); } </script> </head> <body> <button onclick="add()">help</button> </body> </html>
代码括号写错了
function app2(x,y) { var sum,x,y; sum = x * y; return sum; } var req1 = 5*6; var req2 = 2*3; var sumq = req1+req2; document.write("req1的值:"+req1+"<br/>"); document.write("req2的值:"+req2+"<br/>"); document.write(req1+"与"+req2+"和:"+sumq);
能用简洁的方式写 尽量用简洁的方式,减少字符串拼接 减少内存等都需要考虑
(⊙o⊙)…好厉害,
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>help</title>
<script type="text/javascript">
function add2(x,y){
var sum,x,y;
sum = x+y;
return sum;
}
result1=add2(3,4);
result2=add2(5,6);
sumall=result1+result2;
function show(){
document.write("输出:" + result1 + "<br/>");
document.write("输出:" + result2 + "<br/>");
document.write("总和:" + sumall);
}
</script>
</head>
<body>
<button value="输出值" onclick="show()">help</button>
</body>
</html>
首先onclick=“add()”调用函数名错了,。然后没有调用到结果所有没有显示出答案