如何在JavaScript中打開新窗口並插入HTML數據和動態內容值,最後打印打開的窗口頁面。使用動態HTML頁面在JavaScript中打開窗口
- 打開的窗口中必須有每行2卡(取決於隱藏的表),
- 像 - 打開的窗口都會有,如果在我的藏表(tblPrintCards)有1個或2行2個身份證(HTML代碼)單行。
我的JavaScript代碼:
function generateIDCardForPrint() {
/** get all data **/
var oTableExt = $('#tblPrintCards').dataTable();//hide jquery table have data//(photo base64 string,name)
var tablerows = $('#tblPrintCards tr').size();
/** Finding how many rows */
var tblTr = (tablerows/2);
var t = document.createElement('table');
t.width = "100%";
var row = document.createElement('tr');
var td = document.createElement('td');
var ImageID = "data:image/jpg;base64," + aData[0][4];
var images = new Image();
images.src = ImageID;
images.id = "EmpImage";
$('#empImages').html(images);
$('#empImages img').css("height", "80px");
$('#empImages img').css("width", "80px");
$('#empName').text(aData[0][2]);//Hello HTML
var HtmlCode = $('#callID').html();//calling HTML Code static content
td.innerHTML = HtmlCode;
td.align = "left";
row.appendChild(td);
t.appendChild(row);
//Fetch element where table is created & append
var id = document.getElementById("tbl");
//adding table to html code.
tbl.appendChild(t);
alert(t.innerHTML)
var myWindow = window.open("", "MsgWindow", "width=1256, height=300");
myWindow.document.write(t.innerHTML);
myWindow.print();
}
我的HTML代碼
<div id="idCard">
<div class="photoBox">
<img src="images/photo.jpg" alt=""></div>
<div class="clear"></div>
<div class="detailBox">
<label><strong>HERE Dynamic Name<strong></label>
</div>
<div class="clear">
<!-- idCard ends here -->
</div>
</div>
- 基於以上都沒有輸出HTML(卡)會在新的窗口。隱藏表中的行,(如果2行數據1row卡,如果4行數據2個卡)
*, html, body { box-sizing:border-box; }
body { margin:50px;}
.clear { clear:both; }
#idCard {
\t width:310px;
\t padding:10px;
\t border:2px solid #000;
\t box-sizing:border-box;
\t font-family:Arial, Helvetica, sans-serif;
}
#idCard label {
\t display:block;
\t font-size:13px;
\t margin:0 0 5px 0;
}
#idCard .photoBox {
\t width:80px;
\t height:60px;
\t background:#306;
\t float:right;
\t border:0px solid red;
}
#idCard .detailBox {
\t width:150px;
\t height:60px;
\t margin:0px 0 0px 0;
\t border:0px solid red;
\t float:right;
\t padding:15px 0 0 0;
}
<div id="idCard">
<div class="photoBox"><img src="images/photo.jpg" alt=""></div>
<div class="clear"></div>
<div class="detailBox">
<label><strong>Here Dynamic Name<strong></label>
</div>
<div class="clear"><!-- idCard ends here --></div>
</div>
樣品打開新寡婦圖像是:
什麼是您的實際問題? – AFract 2015-02-06 13:47:46
我無法使用動態數據打開html內容。並且它的窗口必須取決於行的數目。上面的示例o/p圖像僅在3行中打印5行。 – Hydrogen 2015-02-06 13:55:01
'tbl'沒有出現定義? ,請參閱'tbl.appendChild(t);'? – guest271314 2015-02-06 15:01:36