我正在使用下面的 javascript 从一些文本框中收集值,进行一些计算并将结果显示为 innerhtml 内容
window.onload = function () {
var left = document.getElementById('mem_count');
var right = document.getElementById('siz_single');
var result = document.getElementById("disp_siz");
function check(a, b, elem) {
var txt = '';
if (a === 0 && b === 0) {
}
else if (a !== 0 && b === 0) {
txt = "Enter size of single device in above column"
}
else if(a == 0 && b !== 0){
txt = "Enter Meta member count in above column "
}
else {
var c = 1 +a
txt = "Your meta device size is " + (c*b) +" MB" + " = " + (c*b/1024) +" GB ";
}
disp_siz.innerHTML = txt;
}
mem_count.onkeyup = calc;
siz_single.onkeyup = calc;
function calc() {
var a = parseFloat(mem_count.value) || 0;
var b = parseFloat(siz_single.value) || 0;
check(a,b, this);
}
}
并且输出将显示在 div 之间
<div id="disp_siz"><-----above output will come here----></div>
此 div 是 html 表单的一部分。提交表单后,我可以将所有其他表单值保留在同一字段中。但无法显示以上输出。它只是清除我的价值观。无论如何我可以在表单提交后将此javascript变量值回显到同一字段吗?