我下面的所有代码部分都显示了我从 ajax 提供数据的表,我的数据显示在动态创建的表内的自定义弹出窗口中;在自定义弹出窗口中,在打印按钮单击上有一个打印按钮我想打印填充有 ajax 数据的表格,该表格以表格格式显示在要打印的同一弹出窗口中。请帮我。
function printPreview(i){
var id=i;
var flag=new Array();
if(checkstatus[i]=="B"){
send={address:'http://192.168.1.22:8082/oracledetail/test.php?result=8&table_code='+tableCode[i]}
$.ajax({
type:"POST",
url:"dummytest.php",
data:send,
success: function(data)
{
//alert(data);
//centering with css
centerPopup();
//load popup
loadPopup();
$('#popupContact').html("<a id='popupContactClose'>X</a><h1>Print Bill</h1>"+
"<center>"+
"<table id='printView' cellspacing='15px'>"+
"<tr class='rows'>"+
"<td><b><font size='+1'>Sr. No</font></b></td>"+
"<td><b><font size='+1'>Item Name</font></b></td>"+
"<td><b><font size='+1'>Quantity</font></b></td>"+
"<td><b><font size='+1'>Price/Item</font></b></td>"+
"<td><b><font size='+1' style='padding-left:10px;'>Qty*Price</font></b></td>"+
"</tr>"+
"</table>"+ "<br/> <input id='print' type='button' value='Print Bill' />" +
"</center>"
);
$("#popupContact").delegate('#print',"click",function(){
var tabcode=tableCode[id];
printBill(tabcode);
});
$("#popupContact").delegate('#popupContactClose',"click",function(){
disablePopup();
location.reload();
});
var total = 0;
var responseString=data.split(",");
var len= responseString.length;
for(var i=0;i<len-1;i++){
var orderDetails=responseString[i].split("~");
itemName[i]=orderDetails[0];
itemQuantity[i]=orderDetails[1];
priceperItem[i]=orderDetails[2];
itemtotalPrice[i]=orderDetails[3];
total += parseInt(itemtotalPrice[i]);
$('#printView').append("<tr class='rows'> <td class='srno'><font size='+1' style='text-align=center;'>"+(i+1)+"</font></td> <td class='itemname'><font size='+1'>"+itemName[i]+"</font></td> <td class='quantity'><font size='+1'>"+itemQuantity[i]+"</font></td> <td class='price'> <font size='+1'>"+priceperItem[i]+"</font></td> <td class='itemtotalprice'><font size='+1'>"+itemtotalPrice[i]+"</font></td> </tr>");
if(i==len-2){
$('#printView').append("<tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> <label> <h3 > Total Bill : "+ total +" </h3> </label>");
}
}//for ends.
}//function ends
}); //ajax ends
}//if ends
else{
$('#popupContact').html("<center><h2>Billing Request Not Yet Generated<h2></center>");
}
}//function ends..
这是我的显示数据的弹出窗口,并且只想在此自定义中打印此数据:
实际上,当我单击打印时,我正在执行以下打印代码:
$("#popupContact").delegate('#print',"click",function(){
var tabcode=tableCode[id];
printBill(tabcode);
var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
var content_innerhtml = document.getElementById("#printView").innerHTML;
var document_print=window.open("","",display_setting);
document_print.document.open();
document_print.document.write(content_innerhtml);
document_print.print();
document_print.document.close();
location.reload();
});
但是当我调试它时,它在这一行显示错误:
line: --> `var content_innerhtml = document.getElementById("#printView").innerHTML;`
错误:-->document.getElementById("#printView") 为空
并进一步执行停止并直接location.reload();
重新加载页面。
请帮我。