我需要使用以下域名:
“尊敬的用户名,您输入的第一个数字是第一个数字,第二个是第二个数字。如果将这两个数字相乘,我们将得到
到目前为止,我已经明白了:
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>
答案 0 :(得分:1)
有可以根据需要运行的代码。如果要在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>