我有一個div
,其中我可以通過更改其十六進制值來控制顏色,但是如何將其打印爲我選擇的顏色而不是原始顏色I曾經在div
?如何使用jQuery或JavaScript打印更改的div
例如:我div
是白色。我改變了顏色紅色和我有一個按鈕,可以讓我打印div
,但它表明我,我打印白色div
代替紅色之一。
<script language="JavaScript">
var gAutoPrint = true; // Tells whether to automatically call the print function
function printSpecial()
{
if (document.getElementById != null)
{
var html = '<HTML>\n<HEAD>\n';
if (document.getElementsByTagName != null)
{
var headTags = document.getElementsByTagName("head");
if (headTags.length > 0)
html += headTags[0].innerHTML;
}
html += '\n</HE>\n<BODY>\n';
var printReadyElem = document.getElementById("printReady");
if (printReadyElem != null)
{
html += printReadyElem.innerHTML;
}
else
{
alert("Could not find the printReady function");
return;
}
html += '\n</BO>\n</HT>';
var printWin = window.open("","printSpecial");
printWin.document.open();
printWin.document.write(html);
printWin.document.close();
if (gAutoPrint)
printWin.print();
}
else
{
alert("The print ready feature is only available if you are using a browser. Please
update your browser.");
}
}
</script>
這是我的按鈕,並選擇div
:
<div id="printReady">
div I want to print
</div>
<a href="javascript:void(printSpecial())" style="position:absolute">Print this Page</a>
附加樣式標籤? – mplungjan