2017-05-02 94 views
0

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

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; 
       }     
     } 
+0

有什么问题吗? :) – Ferus7

+0

经过计算,我想在新窗口显示结果。我在问如何创建弹出窗口来显示函数的结果 –

+0

您可以使用隐藏的div,并在解析数据时显示它,或者您可以使用框架 – Ferus7

回答

1

有多种方式做它,我也假设你正在寻找一个新的窗口,而不是一个模式或弹出窗口。对于您可以使用window.open &更新的价值有

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

DEMO

编辑

首先创建模式

<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> 

一个DOM 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

+0

我想在弹出的窗口中显示resutls。善意启迪我的模态 –

+0

谢谢它的帮助。我想要它像生成一个报告。当我点击按钮

+0

当我使用相同的按钮来计算和显示模态。模态不显示。 –

1

保持一个隐藏的div在HTML并设置绝对位置的div显示/隐藏它使用JavaScript“的style.display”属性点击。

要显示的div使用

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

要隐藏的div

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

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

相关问题