【发布时间】:2019-08-13 12:50:39
【问题描述】:
我的代码正在运行。但是当确认框出现时,我按下“确定”按钮,然后我放置数字及其工作。但如果我按下“取消”按钮放置数字,然后什么也没有发生。
var responce;
var n1, n2, n3, n4, sum;
var m1, m2, mion;
responce = window.confirm("Click OK to add,\nClick Cancel to subtract");
if (responce) {
function add(number1, number2, number3, number4) {
sum = n1 + n2 + n3 + n4;
document.write("Adding your numbers gives you the effect of:" + sum);
}
n1 = parseFloat(prompt("Enter a Number", "0"));
n2 = parseFloat(prompt("Enter a second number", "0"));
n3 = parseFloat(prompt("Give a third number", "0"));
n4 = parseFloat(prompt("Enter a fourth number", "0"));
} else {
function noadd(number5, number6) {
mion = m1 - m2;
document.write("Subtracting your numbers is the result that is:" + mion);
}
m1 = parseFloat(prompt("Enter a Number", "0"));
m2 = parseFloat(prompt("Enter a second number", "0"));
}
add(n1, n2, n3, n4);
noadd(m1, m2);
【问题讨论】:
-
if i press the "cancel" button place the numbers and then nothing happens你希望cancel做什么? -
当我按下取消按钮时,我将放置 2 个数字(例如 50 和 20 )并且该函数将执行 50 - 20 = 30 我的问题是我放置了数字并且没有显示
-
您是根据条件声明函数,然后同时调用它们,因此其中一个必须未声明
-
也不要使用 document.write - 如果你在页面加载后这样做,页面会被擦除。而是使用一些容器的 innerText
标签: javascript confirm