Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从网页打印所选数据_Javascript_Html_Css - Fatal编程技术网

Javascript 从网页打印所选数据

Javascript 从网页打印所选数据,javascript,html,css,Javascript,Html,Css,我想打印所选div的数据,而不是整页, 我使用的是window.print(),但它会打印整个网页。 <link rel="stylesheet" type="text/css" media="print" href="print.css" /> 如何编写打印样式表,并将其设置为显示页面上的相关元素。如果您事先知道要打印哪些片段,可以使用基于媒体的CSS在打印时隐藏页面中不需要的片段。看看 按照以下示例所示执行: <html> <head>

我想打印所选
div
的数据,而不是整页, 我使用的是
window.print()
,但它会打印整个网页。


<link rel="stylesheet" type="text/css" media="print" href="print.css" />

如何编写打印样式表,并将其设置为显示页面上的相关元素。

如果您事先知道要打印哪些片段,可以使用基于媒体的CSS在打印时隐藏页面中不需要的片段。看看


按照以下示例所示执行:

   <html>
    <head>
    <style type="text/css" media="print">
    @media print
    {
    #non-printable { display: none; }
    #printable {
    display: block;
    width: 100%;
    height: 100%;
    }
    }
    </style>
    </head>
    <body>
    <div id="printable" >
    Your content to print
    </div>
    <div id='non-printable'>
    this is not printable section
    </div>
    <input type="button" id="non-printable" class=normaltext onclick="JavaScript:window.print();" value="print" />
    </body>
    </html>

@媒体印刷品
{
#不可打印{显示:无;}
#可打印{
显示:块;
宽度:100%;
身高:100%;
}
}
您要打印的内容
这是不可打印的部分
有关更多详细信息或下载,请访问网站:


删除JSP和Java标记。这与他们无关。可能是添加JavaScript标记。可能是的重复项