javascript - 隐藏文本不能在 IE、Jquery 中显示或选择或打印

标签 javascript jquery css

HTML:

<button id="hide_some_text">Hide</button>
<div id="first">my name is Sea Mist and iam 19 years old</div>
<div id="second" style="display: none">This is the hidden text to be printed and selected only when button is pressed</div>

JQUERY:

$("#hide_some_text").click(function(){
$("#second").toggle();
});

我想要什么:

如果 div 标签“second”下的文本仅可见,则应选择并打印它 (请注意,我在 IE 中工作),如果 div 标签“second”下的文本被隐藏,那么当我执行 Ctrl+A -> Ctrl + V 时,它不应该被选中,并且当我进行打印预览 < 时,也不应该显示它。/p>

注意:我使用 IE,这些问题不会出现在 mozzila 或 chrome 中,但由于限制我必须使用 IE,所以我需要 IE 特定的解决方案

最佳答案

在 JavaScript 中执行以下操作:

var cache;
$("#hide_some_text").click(function(){
    if($("#second").is(":visible")) { //if it's not hidden
        cache = $("#second").html(); //cache the HTML
        $("#second").hide().html(""); //hide and empty HTML
    }
    else { //else, it's hidden
        $("#second").show().html(cache); //show and get back HTML
    }
});
$(document).ready(function() {
    $("#hide_some_text").click();
});

关于javascript - 隐藏文本不能在 IE、Jquery 中显示或选择或打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328815/

相关文章:

javascript - 通过 http 传输大文件 (>100MB) 的最佳方式

javascript - gulpfile.js - 任务不在 gulp 文件中错误

javascript - 点击按钮后 jquery 谷歌地图不会重新加载

jquery - 在 jQuery 中动画化 <li> 移除

css - Wordpress 菜单居中对齐且间距均匀

javascript - 如何在按键时自动填充文本字段

javascript - ASP MVC 网格非因素 - 将新行添加到网格表

javascript - 创建并填充 &lt;style&gt; 元素

css - 使用 3d css 转换翻转时,Firefox 不会隐藏卡片的背面

javascript - jQuery keydown 创建列表