是否可以在HTML / Javascript中打印div标签中的元素? [英] Is it Possible to Print elements in a div tag in HTML/Javascript ?
本文介绍了是否可以在HTML / Javascript中打印div标签中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个项目正在进行,需要打印功能。此打印功能基本上只打印一个包含所有填充数据的表单。我知道
Hi All,
I have got project that I am working on that requires a print function. This print function basically just prints a form with all the data that is filled up. I am aware of the
onclick="window.print()
但是这个功能打印出整个页面,更像打印打印预览。
有没有什么方法可以用html / javascript聚焦和打印表格?或者可以指定并打印div标签中包含的代码元素?
but this function prints out the entire page , more like a print print preview.
Is there any way I can focus and print the form in html/javascript? or is possible to specify and just print code elements that are contained in a div tag??
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div> //can some how specify to only print elements in this div??
<label> First Name:</label>
<input type="text"> <br>
<label> Last Name: </label>
<input type="text">
</div> // up to here...
<button onclick="window.print()" > Print </button> //onlick here prints the whole page, which is not what i am looking for.
</body>
</html>
谢谢你提前帮助。
Thank you for your help in advance.
推荐答案
参考 - 打印特定div的内容 [ ^ ]。
逻辑是在另一个窗口中打开该div然后打印。就是这样。
Refer - Printing content of a particular div[^].
Logic is to open that div in another window and then print. That's it.
你可以使用jquery库实现这个目标
jquery Library
和
Jquery插件
写这个....
You can achieve this using the jquery Library
jquery Library
and
Jquery Plugin
Write this....
<head>
<title>Invoice</title>
<script src="AdminPanel/js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="js/jquery.PrintArea.js" type="text/javascript"></script>
<script type="text/javascript">
( document )。ready( function (){
(document).ready(function () {
这篇关于是否可以在HTML / Javascript中打印div标签中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文