在此代码段中,我想总结插入到prpmpts中的值(数值是其他明智的警报错误输入)。但我的问题是,当我连插数它提醒输入错误,而不是和值如何在javascript中添加2个数字值
function sumation(a,b){
if (typeof a == "number" && typeof b == "number")
return (a + b);
else
alert("wrong input")
}
window.onload = function(){
var val1 = prompt("insert first number","");
var val2 = prompt("insert second number","");
var result = sumation(val1,val2);
alert(result);
};
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script src="newjavascript.js"></script>
</body>
</html>
'typeof运算(一)'和'typeof运算(B)'是一个'string',因此错误的输出 –
[使用jQuery](https://howtodoinjava.files.wordpress.com/2013/04/use-jquery.gif) – vlaz