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/