[英]Javascript multiple functions
我需要使用以下内容创建域:
“尊敬的用户姓名,您输入的第一个数字是第一个数字,第二个数字是第二个数字。如果我们将这两个数字相乘,我们得到
到目前为止,我已经得到了这个:
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.