2013-02-28 92 views
0

這是帶表格的簡單頁面。我想打印它按鈕點擊。但腳本不起作用。JavaScript window.print()不起作用

<html><head><style>th{background-color:#000}table, th, td { border: 1px solid black; } </style></head><body><center> 
<TABLE id=highlight class=hilite border=1 cellSpacing=5 cellPadding=4><THEAD style="COLOR: white"> 
<TR> 
<TH colSpan=2>MINI STATEMENT</TH></TR></THEAD> 
<TBODY> 
<TR> 
<TD class=row width="15%"><B>Account Id</B></TD> 
<TD class=row><B>A000000003</B></TD></TR> 
<TR></TR> 
<TR> 
<TD class=row width="15%">Your Previous Balance</TD> 
<TD class=row width="15%">2539.62</TD></TR> 
<TR></TR> 
<TR> 
<TD class=row width="15%">Your Current Balance</TD> 
<TD class=row width="15%">2538.62 </TD></TR></TBODY></TABLE><input type='button' onClick='window.print()' value='Print'></center></body></html> 

這是一個虛擬項目的維護代碼,所以只是忽略標準和約定:p練習。

+0

我得到它在Firefox 19.0,該瀏覽器? – arjuncc 2013-02-28 04:19:10

+0

它正在working.check在鉻。 – Amrendra 2013-02-28 04:19:19

+0

我在做IE8 :( – Mahesha999 2013-02-28 04:21:29

回答

1

嘗試像這樣...

<html> 
<head> 
<script type="text/javascript"> 
    function openWin() 
    { 
    var myWindow=window.open('','','width=200,height=100'); 
    myWindow.document.write("<p>This is 'myWindow'</p>"); 
    myWindow.document.close(); 
    myWindow.focus(); 
    myWindow.print(); 
    myWindow.close(); 

    } 
</script> 
</head> 
<body> 

<input type="button" value="Open window" onclick="openWin()" /> 

</body> 
</html> 

檢查這裏.. http://jsfiddle.net/Q5Xc9/1/