我有这些标签:
<a href = "#" title="Print" role="button" id="print" onclick="print()" class = "btn btn-default btn-sm"><i class="fa fa-print"></i> </a>
<ul class="nav nav-tabs">
<li><a href="#floor1" data-toggle="tab" data-id="1"><span>1st Floor</span> </a> </li>
<li><a href="#floor2" data-toggle="tab" data-id="2"><span>2nd Floor</span> </a> </li>
<li><a href="#floor3" data-toggle="tab" data-id="3"><span>3rd Floor</span> </a> </li>
</ul>
<div class="tab-content" id="tabContents">
<div class="table-responsive tab-pane fade active in" id="floor1">
<p>Details on floor 1</p>
</div>
<div class="table-responsive tab-pane fade" id="floor2">
<p>Details on floor 2</p>
</div>
<div class="table-responsive tab-pane fade" id="floor3">
<p>Details on floor 3</p>
</div>
</div>
每当我点击打印锚时,我都想打印当前活动标签的内容。但我有一个问题,如何将当前标签发送到打印功能。谁能帮我吗?感谢。
我有这个打印功能。
function print()
{
var divToPrint=document.getElementById("floor1").innerHTML;
newWin= window.open("");
newWin.document.write(divToPrint);
newWin.print();
newWin.close();
}
答案 0 :(得分:1)
尝试使用
<a ...onclick="return print()" ....></a>
OR
<input type="button" onclick="print()" .......>
代替锚标记