2014-06-23 85 views
0

打印我使用這個代碼從結果顯示在同一窗口爲形式的一種形式提交表單的數據的彈出和彈出窗口

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" /> 
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div> 
<script type="text/javascript"> 
    function submit() 
    { 
     var name = document.getElementById("name").value; 
     document.getElementById("info").innerHTML = " My Name is "+name+" "; 
    return false; 
    } 
</script> 

得到提交的數據。 我想顯示在彈出窗口中顯示輸出,並能夠在一次點擊將打印彈出內容的主窗口

edit: just to clarify more. 

form submitted > open a new window > displays the entered results 

感謝

+0

所以打開一個新的窗口(window.open)和寫入(文件寫入)。 – epascarello

+0

你能修改這段代碼嗎,謝謝 – user3743685

+0

http://jqueryui.com/dialog/#modal – ewizard

回答

0

鏈接打印按鈕那麼你可以修改這樣的代碼:

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" /> 
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div> 
<script type="text/javascript"> 
    function submit() 
    { 
     var name = document.getElementById("name").value; 
     document.getElementById("info").innerHTML = " My Name is "+name+" "; 
     var r = window.confirm(" My Name is "+name+" .Click Ok To Print"); 
     if (r == true) { 
      x = window.print(); 
     } 
    return false; 
    } 
</script> 

希望這可以滿足您的目的。

+0

謝謝,通過彈出窗口我的意思是新窗口。 – user3743685

+0

試試這個,而不是......... var myWindow = window.open(「」,「MsgWindow」,「width = 200,height = 100」); \t \t \t \t myWindow.document.write(「

我的名字是」+ name +「

」); – arp

+0

非常感謝您的幫助 – user3743685

0

我想你想要像

<input id="name" name="name" type="text" class="auto-style8" style="width: 70%" /> 
<button id="singlebutton" name="singlebutton" class="btn btn-primary" onclick="return submit();">Submit</button> 
<div id="info"></div> 
<script type="text/javascript"> 
    function submit() 
    { 
     var name = document.getElementById("name").value; 
     var output = " My Name is "+name+" "; 
     var myWindow = window.open("data:text/html," + encodeURIComponent(output), 
        "_blank", "width=200,height=100"); 

     x = window.print(); 

     return false; 
    } 
</script> 

我以前this作爲靈感:)