简体   繁体   English

隐藏身体标签,但仍显示div

[英]hide body tag but still show a div

    <script>
    $(document).ready(function(){

    $("#print").click(function(){
        $("body").hide();
        $("p").show();
        window.print();
        $("body").show();            
    });        
});
</script>
</head>
<body>

<p>THIS SHOULD BE PRINTED </p>

<button >Hide</button>
<button >Show</button>
<button id="print">print</button>    
</body>

given is a sample code. 给出的是示例代码。 Clicking on print button should hide body of page except the values inside "p" tags. 单击“打印”按钮应隐藏页面主体,但“ p”标记中的值除外。 need help as to how to achieve this ? 需要帮助如何实现这一目标? is there some way of making "p" tag or "div" tag act as body temporarily ? 有什么方法可以使“ p”标签或“ div”标签暂时充当主体?

使用下面给定的功能首先隐藏body标签的所有子项,然后显示所需的子项

$("body").find("*").hide();

I would structure your application differently as you can't show something contained within the element you have hidden. 我将以不同的方式构造您的应用程序,因为您无法显示隐藏元素中包含的内容。

<body>
    <div id="hide-me"></div>
    <p id="show-me">THIS SHOULD BE PRINTED</p>
</body>

and change your logic to something like this... 然后将您的逻辑更改为类似的内容...

$(document).ready(function(){
    $("#print").click(function(){
        $("#hide-me").hide();
        $("#show-me").show();
        window.print();
        $("#hide-me").show();            
    });
});

It can be risky to hide everything in the page. 隐藏页面中的所有内容可能会有风险。 Also, the approach makes you ahve to add the content after hiding the body. 同样,该方法使您可以在隐藏正文之后添加内容。

A better approach is to make the content you want come to the front, fill up the whole screen, and hide everything else behind it without deleting. 更好的方法是使所需的内容排在最前面,填满整个屏幕,然后将其他所有内容隐藏在其中而不删除。

And it's very simply to do so. 这样做非常简单。

 $(function() { $('.show-print').on('click', function() { $('.print-container').addClass('active-print'); }); }); 
 .print-container { position: fixed; background: white; top: 0; left: 0; bottom: 0; right: 0; } .print-container:not(.active-print) { display: none; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p> Normal body content </p> <button class="show-print">Print</button> <div class="print-container"> <div class="print-content"> I'm Print. I'm stronger than BODY! </div> </div> 

显示/隐藏<div>标签不工作</div><div id="text_translate"><p>我有一个超链接,它应该在 onclick 事件期间一一调用 3 个 JS 函数。</p><pre> &lt;form name = "bulkcontactfrm" method="POST" action="&lt;%= servletPath %&gt;&gt; &lt;div id="saveDiv" layoutAlign="top" style="display:block;"&gt; &lt;table id="" align="left" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt; &lt;td&gt; &lt;a href="javascript:void(0);" onclick="isAllowedToResubscribe(document.bulkcontactfrm); manipulateDIV(document.bulkcontactfrm); resubscribeCall(document.bulkcontactfrm);"&gt;&amp;#160;Re-Subscribe&lt;/zoniac:roundrect&gt;&amp;#160;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div id="loadingDiv" class="cellWhiteBGFont" layoutAlign="top" style="display: block;"&gt;&lt;p&gt;&lt;img src="&lt;%=ImageMappingManager.getImageName("imgLoading")%&gt;" name = "b1"&gt;&amp;nbsp;&amp;nbsp;&lt;font size='3'&gt;&lt;b&gt;Please wait...&lt;b&gt;&lt;/font&gt;&lt;/p&gt; &lt;/div&gt; &lt;/form&gt;</pre><p> JS函数如下:</p><pre> // First function validate the data using ajax call function isAllowedToResubscribe(form) { //Client validation takes here processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailValidationDetails',emilIDStr,sourcefromStr); } // Second function hide the content in UI and show the Processing image in &lt;DIV&gt; tag function manipulateDIV(form) { hideSaveDiv(); showLoadingDiv(); } function hideSaveDiv() { //hide the Re-Subscribe hyperlink document.getElementById('saveDiv').style.display='none'; } function showLoadingDiv() { //show the Processing image document.getElementById('loadingDiv').style.display='block'; } // Third function is for form submit using ajax call function resubscribeCall(form) { //processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailDetails',emilIDStr,sourcefromStr); }</pre><p> 单击超链接验证 function 调用并获取成功后,出现构造消息,单击构造上的确定。 但是&lt;DIV&gt;标签并没有被隐藏,所以没有加载进度图像。</p></div> - show/hide the <div> tag is not working

暂无
暂无

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

相关问题 显示/隐藏div标签javascript - Show/Hide div tag javascript 显示/隐藏<div>标签不工作</div><div id="text_translate"><p>我有一个超链接,它应该在 onclick 事件期间一一调用 3 个 JS 函数。</p><pre> &lt;form name = "bulkcontactfrm" method="POST" action="&lt;%= servletPath %&gt;&gt; &lt;div id="saveDiv" layoutAlign="top" style="display:block;"&gt; &lt;table id="" align="left" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tr&gt; &lt;td&gt; &lt;a href="javascript:void(0);" onclick="isAllowedToResubscribe(document.bulkcontactfrm); manipulateDIV(document.bulkcontactfrm); resubscribeCall(document.bulkcontactfrm);"&gt;&amp;#160;Re-Subscribe&lt;/zoniac:roundrect&gt;&amp;#160;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div id="loadingDiv" class="cellWhiteBGFont" layoutAlign="top" style="display: block;"&gt;&lt;p&gt;&lt;img src="&lt;%=ImageMappingManager.getImageName("imgLoading")%&gt;" name = "b1"&gt;&amp;nbsp;&amp;nbsp;&lt;font size='3'&gt;&lt;b&gt;Please wait...&lt;b&gt;&lt;/font&gt;&lt;/p&gt; &lt;/div&gt; &lt;/form&gt;</pre><p> JS函数如下:</p><pre> // First function validate the data using ajax call function isAllowedToResubscribe(form) { //Client validation takes here processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailValidationDetails',emilIDStr,sourcefromStr); } // Second function hide the content in UI and show the Processing image in &lt;DIV&gt; tag function manipulateDIV(form) { hideSaveDiv(); showLoadingDiv(); } function hideSaveDiv() { //hide the Re-Subscribe hyperlink document.getElementById('saveDiv').style.display='none'; } function showLoadingDiv() { //show the Processing image document.getElementById('loadingDiv').style.display='block'; } // Third function is for form submit using ajax call function resubscribeCall(form) { //processAjaxRequestPost('ajaxRequestPost','SimpleHandler','getResubscribeEmailDetails',emilIDStr,sourcefromStr); }</pre><p> 单击超链接验证 function 调用并获取成功后,出现构造消息,单击构造上的确定。 但是&lt;DIV&gt;标签并没有被隐藏,所以没有加载进度图像。</p></div> - show/hide the <div> tag is not working 在 HTML 中隐藏和显示 Div 标签 - Hide and Show Div tag in HTML 在选择标记上显示/隐藏div - Show/hide div on select tag jQuery-使用select标签显示和隐藏DIV - jquery - show and hide DIV with the select tag jQuery从另一个div内部将div显示/隐藏在主体中 - jQuery show/hide div in body from inside another div Jquery 点击输入框显示div,点击正文隐藏div - Jquery click input field show div, click body hide div 显示/隐藏错误 div function 检测 I 标记为 div - Show/hide error div function detect I tag as a div 显示/隐藏div并仍然使用内容 - HTML / JS - Show / Hide div and still function with content inside - HTML / JS 单击显示 div 但再次隐藏 + 使主体 position 停留 - clicking for show div but hide again + make body position stay
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM