简体   繁体   English

在打印中显示特定div的内容

[英]display content from specific div on print

I want to print some content from firefox. 我想从Firefox打印一些内容。 I already have inside html page <div id="printContent"></div> which is hidden by default. 我已经在html页面<div id="printContent"></div> ,该页面默认为隐藏。 Using css I display this div with injected content on printing like 使用CSS我在打印时显示此div并注入内容

@media print {    
    #printContent{
        display:block;
    }
}

but on print preview I'm getting some other page div, not just this #printContent . 但是在打印预览中,我得到了其他页面div,而不仅仅是这个#printContent What should I do to get only #printContent on firefox print preview? 我应该怎么做才能在firefox打印预览上仅获取#printContent

Hide the other content using display:none in media selector - I'd suggest your #printContent div be a child of body, then you can 使用display:none在媒体选择器中隐藏其他内容-建议您将#printContent div设为body的子代,然后

@media print {    
    body>* {
        display:none !important;
    }
    body>div#printContent{
        display:block !important;
    }
}

edit: added !important - depending on other CSS you may or may not need !important 编辑:添加了!important-取决于您是否需要!important其他CSS

显示特定的<div> setTimeout() 处的内容</div><div id="text_translate"><p>在下面的代码中,我正在使用setTimeout()对我的后端 node.js 应用程序进行 API 调用,该应用程序每 5 秒调用一次我的 AJAX。 在我的 AJAX 成功中,我根据应至少执行一次的特定条件显示divContent1和divContent2 。 之后,在每个setTimeout()调用中,只有divContent2应该是可见的。</p><p> <strong>索引.html</strong></p><pre> &lt;script type="text/javascript"&gt; $(document).ready(function(){ $.ajax({ url: "http://localhost:8070/api/route1", type: 'POST', dataType:'json', success: function(res) { //Some Task } }); $("#myButton").click(function(){ const route2 = function() { $.ajax({ url: "http://localhost:8070/api/route2", type: "POST", dataType: "json", data: { var1: val1 }, success: function (res) { // Various tasks if(res.flag){ $("#divContent1").hide(); $("#divContent2").show(); } else{ $("#divContent1").show(); } //Functions that handle div content data }, beforeSend: function() { $("#divContent1").hide(); $("#divContent2").hide(); }, complete: function() { setTimeout(route2,5000); }, }); }; $(function(){ route2(); }) }); }); &lt;/script&gt;</pre><p> setTimeout() 调用整个route2来处理div内容的所有显示和插入。 但是,要求仅显示第二次调用的divContent2 。</p><p> 寻找解决方案</p></div> - Display a specific <div> content at setTimeout()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 显示特定的<div> setTimeout() 处的内容</div><div id="text_translate"><p>在下面的代码中,我正在使用setTimeout()对我的后端 node.js 应用程序进行 API 调用,该应用程序每 5 秒调用一次我的 AJAX。 在我的 AJAX 成功中,我根据应至少执行一次的特定条件显示divContent1和divContent2 。 之后,在每个setTimeout()调用中,只有divContent2应该是可见的。</p><p> <strong>索引.html</strong></p><pre> &lt;script type="text/javascript"&gt; $(document).ready(function(){ $.ajax({ url: "http://localhost:8070/api/route1", type: 'POST', dataType:'json', success: function(res) { //Some Task } }); $("#myButton").click(function(){ const route2 = function() { $.ajax({ url: "http://localhost:8070/api/route2", type: "POST", dataType: "json", data: { var1: val1 }, success: function (res) { // Various tasks if(res.flag){ $("#divContent1").hide(); $("#divContent2").show(); } else{ $("#divContent1").show(); } //Functions that handle div content data }, beforeSend: function() { $("#divContent1").hide(); $("#divContent2").hide(); }, complete: function() { setTimeout(route2,5000); }, }); }; $(function(){ route2(); }) }); }); &lt;/script&gt;</pre><p> setTimeout() 调用整个route2来处理div内容的所有显示和插入。 但是,要求仅显示第二次调用的divContent2 。</p><p> 寻找解决方案</p></div> - Display a specific <div> content at setTimeout() 如果存在具有特定类别的div,则显示内容 - Display content if there is a div with a specific class 显示DIV中的内容 - Display content from DIV 在Android Webview的HTML中显示特定的div内容 - Display specific div content in a Html from android Webview 使用RegEx查找特定的div并打印内容 - Find specific div with RegEx and print content 打印特定的div内容不显示javascript - print specific div content not showing javascript 根据 URL 显示特定的 div 或内容 - display specific div or content based on URL 我只想打印来自 HTML/JS 页面的特定 div 内容和电子邮件结果? - I want to print only the specific div content and email results from HTML/JS page? 如何在Oracle APEX5中打印PLSql动态内容的特定Div? - How To Print Specific Div Of PLSql Dynamic Content in Oracle APEX5? 具体如何打印 <div> javascript或jquery在新窗口中显示内容? - How to print the specific <div> content in new window using javascript or jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM