javascript - 如何将另一个函数中的数字调用到函数中?

标签 javascript

如何将函数 numOne 中的“x”调用到函数 numTwo 中?有没有更简单的方法来做到这一点?或者如何将 numOne 的结果调用到 numTwo 中?

<!doctype HTML>
<html> 
    <head> 
        <title>Function Testing</title>
    </head> 
    <body>
        <script type="text/javascript">
            function numOne(x, y){
                var x = 3;
                var y = 4;
                var result = x+y;
                numTwo();
            }
            function numTwo(){
                alert(x);
            }
        </script>
    </body> 
</html>

最佳答案

将结果传递给numTwo:

function numOne(x, y){
    var result = x+y;
    numTwo(result);
}

function numTwo(r){
    alert(r);
}

numOne(2, 3);

关于javascript - 如何将另一个函数中的数字调用到函数中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26437417/

相关文章:

javascript - 向 Google map 添加信息框?

javascript - 在列表/ GridView 切换器中默认显示网格

javascript - 更改 Canvas 中描边的颜色

javascript - 使用 proxy_pass 将 NGINX 链接到 Node.js 集群

javascript - 使用 node-windows 打包 Node.js 应用程序作为服务运行

javascript - 无法从 JQuery 获取 xmlhttprequest.responseText

javascript - 从月数中获取天数

Javascript 最小值最大值

javascript - jQuery,在更改时运行函数

javascript - 使用 jquery 延迟 css 转换