JavaScript的:
function getValue(){
var num1 = document.getElementById("firstNum").value;
var num2 = document.getElementById("secondNum").value;
return (num1, num2);
}
function add(){
getValue();
var result = parseFloat(num1) + parseFloat(num2);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我正在创建的是一个从输入框中获取值的计算器.我遇到的问题是我应该如何调用我在getValue()中声明的变量; 函数在我的add(); 用于创建值的函数.
我很感激帮助.