我正在嘗試創建一個'打印'按鈕來打開一個新窗口並在其中顯示一個PHP變量。Jquery - 用當前頁面的內容打開一個新窗口
下面的代碼通過PHP腳本循環多次,但是我看不到要打開窗口時顯示的正確數字(打印鏈接中顯示的數字是正確的 - 但是當新窗口打開時是不正確的)。
<script type='text/javascript'>
jQuery(function($) {
$('a.new-window').click(function(){
var recipe = window.open('','PrintWindow','width=600,height=600');
var html = '<html><head><title>Print Your Ticket</title></head><body><div id="myprintticket">' + $('<div />').append($('#ticket').clone()).html() + '</div></body></html>';
recipe.document.open();
recipe.document.write(html);
recipe.document.close();
return false;
});
});
</script>
<a href="" class="new-window">Print <?php echo $EM_Booking->get_spaces() ?></a>
<div style="display:none;">
<div id="ticket"><?php echo $EM_Booking->get_spaces() ?>
</div>
</div>
如果這是多次循環 - 你有許多#ticket元素。 html元素的ID必須是唯一的。 – tborychowski 2013-03-26 12:48:55