简体   繁体   English

如何为 function 参数分配提示值

[英]How to assign a prompt value to function parameter

So i have this code:所以我有这个代码:

<div class="wrapper">
    <p id="ex"></p>
    <script>
        function celMessager() {
            var celMs = window.prompt("Enter the celsius grades:");
            celMs = parseFloat(celMs);
                if (celMs == null) {
                document.getElementById("ex").innerHTML = "Error.";
            }
            else {
                document.getElementById("ex").innerHTML = celConversor();
            }

        }
    </script>

    <button class="button" type="button" onclick="
     celMessager();
    ">
     Conversor Celsius.
    </button>
</div>

And i want to store the value of the user input (celMs) into the only parameter that celConversor() takes:我想将用户输入(celMs)的值存储到 celConversor() 采用的唯一参数中:

function celConversor(celGrades) {
     fahGrades = (celGrades * 9/5) + 32;
     return fahGrades;
}

So the number that the user enters, become the celsius grades that are going to change into fahrenheit and show it as a paragraph.所以用户输入的数字,就变成了摄氏等级,会变成华氏度,并显示为一个段落。 How can I do this?我怎样才能做到这一点? tried making the celGrades variable = to celMs and celMs to celGrades, but it always returns "NaN" in the paragraph, even after i added the "parseFloat" line.尝试将 celGrades 变量 = 设置为 celMs 并将 celMs 设置为 celGrades,但它始终在段落中返回“NaN”,即使在我添加了“parseFloat”行之后也是如此。

You're getting this error celConversor requires a parameter, but you're not passing any parameters to it.您收到此错误celConversor需要一个参数,但您没有将任何参数传递给它。 Change this line:更改此行:

document.getElementById("ex").innerHTML = celConversor();

to this:对此:

document.getElementById("ex").innerHTML = celConversor(celMs);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将JSF selectBooleanCheckbox的布尔值作为参数分配给java脚本函数? - How to assign a boolean value of an JSF selectBooleanCheckbox as parameter to a java script function? 如何将提示作为对象/函数参数传递 - How to pass a prompt as an object/function parameter 如何从一个jQuery函数获取值并将其分配给另一个函数的参数? - How to take a value from one jQuery function and assign it to a parameter of another function? 如何分配以函数为参数的变量 - How to assign a variable which function takes as a parameter 如何在回调函数中赋值? - How to assign value in the callback function? 在 javascript 如何分配 function 以提示三个 arguments 并将这些 ZDBC11CAA5BDA29F77E6FB4DABD8 结果写入提示 - In javascript how can I assign a function to prompt with three arguments and wirte these arguments in the prompt and get a result 调用javascript参数提示时如何显示 - How to display when the function is called javascript parameter prompt 如何在AngularJS的$ on函数外部给变量赋值? - How to assign value to variable outside the function in $on AngularJS? 如何通过箭头分配数组元素的值 function - How to assign value of array element by a arrow function 如何在javascript中为返回函数的变量赋值 - how to assign a value to a variable of a return function in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM