我创建了一个计算总和值的按钮。计算后,我想在新窗口中显示我的结果,如弹出窗口。以及下拉框中的其他选定值。这是我的代码。
function CalCost(a)
{
var area = a;
var Total_Cost = 0;
var max = 100;
if(a == 1)
{
J = 40;
D = 15;
E = 900;
P = 75;
L = 50;
E = 5;
M = 16;
Pi =8;
Pr = 34;
Ir = 52;
W = 42;
RK = 25;
Sp = 7;
Total_Cost = J+D+E+P+L+E+M+Pi+Pr+Ir+W+RK+Sp;
}
}
有多种方法可以做到这一点,而且我认为您正在寻找一个新窗口,而不是模态或弹出窗口。为此,您可以使用window.open
并更新那里的值
var win = window.open();
win.document.write(Total_Cost);
编辑
首先为模态创建一个dom
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p id ='calValue'></p> // calculated value will be show here
</div>
</div>
JS
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
在此处查看演示
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句