gpt4 book ai didi

javascript - 打印 getElementsByClassName

转载 作者:行者123 更新时间:2023-11-30 17:35:41 29 4
gpt4 key购买 nike

<分区>

我只想打印属于特定类别的部分 html 文件。我设法创建了完成工作的 getElementById 函数,但我似乎无法为 getElementsByClassName 创建相同的函数。我需要能够只打印具有 class="print"的单个 div,而 atm 我只打印 ID。

这是我的 html 代码示例:

    <div id="CCC" title"Checklist"> 
<h2>Checklist</h2>
<div>Content</div>
</div>

<div id="BBB" title="Chapter 1">
<h2 class="Chapter">Chapter 1</h2>
<div><p>Content 2</p></div>

<div>
<table id="Ch1_tab" width="100%" border="1" style="border-color:#D2D2D2; border-collapse:collapse;">
<div id="Q0101" class="print">
<tr>
<td width="41" align="left" valign="top"><div class="QNumber">1.1</div></td>
<td><div class="QText">Name of the vessel:</div></td>
<td width="300"><div class="Response"><input name="Text" type="text" id="vslName" size="31"></div></td>
</tr>
</div>
<div id="Q0102">
<tr>
<td width="41" align="left" valign="top"><div class="QNumber">1.2</div></td>
<td><div class="QText">Vessel IMO Number:</div></td>
<td width="300"><div class="Response"><input name="Text" type="number" id="IMONum" size="10"></div></td>
</tr>
</div>
<div id="Q0107" class="print">
<tr>
<td width="41" align="left" valign="top"><div class="QNumber">1.7</div></td>
<td><div class="QText">How many Load Lines certificates available:</div></td>
<td width="300"><div class="Response"><input name="Text" type="number" id="R0107" size="10"></div></td>
</tr>
</div>
<div id="Q0107" class="print">
<tr>
<td width="41" align="left" valign="top"><div class="QNumber">1.9</div></td>
<td><div class="QText">Date the crew commenced preparation for vetting:</div></td>
<td width="300"><div class="Response"><input name="GenDate" class="GenDate" type="text" id="R0109"></div></td>
</tr>
</div>
</table>
</div>


<iframe name=print_frame width=0 height=0 frameborder=0></iframe>
<p>
<input type="button" value="Print Div" onclick="javascript:printDiv()">
</p>

这是我打印 ID="BBB"的 JS

<script>
printDivCSS = new String ('')
function printDiv() {
window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById('BBB').innerHTML
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()
}
</script>

提前致谢!

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com