gpt4 book ai didi

Javascript 多重函数

转载 作者:行者123 更新时间:2023-11-28 00:42:47 25 4
gpt4 key购买 nike

我需要创建一个包含以下内容的域:

  • 询问用户的姓名。
  • 提示用户输入 1 到 100 之间的数字。
  • 提示用户输入 10 到 20 之间的数字。 <
  • 给出带有以下文本的输出:

"Dear name of user the first number you entered was first number the second was second number. If we multiply these two number we get

到目前为止,我得到了这个:

function myFunction() {
var person = prompt("Please enter your name", "enter name");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}

function addNumbers() {

var val1 = parseInt(document.getElementById("value1").value);
val val2 = parseInt(document.getElementByID("value").value);
var ansD = document.getElementByID("answer");
ansD.value = val1 + val2;
}
<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

最佳答案

有您想要运行的代码。如果你想在 html 页面中输出结果,你可以简单地使用你想要更改的 id 的 innerHTML 方法。

<!DOCTYPE html>
<html>
<body>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
var person = prompt("Please enter your name");
var firstN = prompt("Please enter a number between 1 and 100");
var secondN = prompt("Please enter a number between 10 and 20");
document.getElementById("demo").innerHTML = "Dear "+person+" the first number you entered was "+firstN+" the second was "+secondN+". If we multiply these two number we get "+(firstN*secondN);
}
</script>

</body>
</html>

关于Javascript 多重函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52475407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com