簡體   English   中英

Javascript多種功能

[英]Javascript multiple functions

我需要使用以下內容創建域:

  • 詢問用戶他或她的名字。
  • 提示用戶輸入 1 到 100 之間的數字,兩者都包括在內。
  • 提示用戶輸入 10 到 20 之間的數字,兩者都包括在內。 <
  • 給出帶有以下文本的輸出:

“尊敬的用戶姓名,您輸入的第一個數字是第一個數字,第二個數字是第二個數字。如果我們將這兩個數字相乘,我們得到

到目前為止,我已經得到了這個:

 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM