结果显示在新 window

result display in the new window

我创建了一个计算总和值的按钮。计算后,我想在新的 window 中显示我的结果,如弹出窗口 window 以及下拉框中的其他选定值。这是我的代码。

 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 而不是模式或弹出 window。为此,您可以使用 window.open 并在那里更新值

var win = window.open();
win.document.write(Total_Cost);

DEMO

编辑

首先为模态

创建一个dom
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</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";
    }
}

查看演示 here

在你的 HTML 中保留一个隐藏的 div 并将绝对位置设置为 div,Show/Hide 单击它时使用 JavaScript "style.display" 属性.

要显示 div 使用

document.getElementById("myDIV").style.display = "";

隐藏div

document.getElementById("myDIV").style.display = "none";

或者您可以使用 JQuery 对话框 https://jqueryui.com/dialog/#animated