它打印" printme"的innerHTML。 div,我也喜欢在页面上打印任何alt标签:
<script type="text/javascript">
var win=null;
function printIt(printThis)
{
win = window.open();
self.focus();
win.document.open();
win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
win.document.write(printThis);
win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
win.document.close();
win.print();
win.close();
}
</script>
body html:
打印
仅打印页面的这一部分
答案 0 :(得分:0)
使用&#34; getAttribute&#34;如果你在谈论一个img标签,我会认为你是。
var imgAlt = document.getElementById("theImageID").getAttribute("alt");
document.write(imgAlt);