简体   繁体   English

隐藏文本中的Ctrl + F:显示文本

[英]Ctrl+F in hidden text: reveal the text

I have containers with multiple lines but only the first one visible ( overflow:hidden ). 我有多行的容器,但只有第一个可见( overflow:hidden )。 The container is expandable upon a click. 容器可以在点击时展开。 (See https://stackoverflow.com/a/6972830 and the jsFiddle http://jsfiddle.net/JUtcX/2/ ) (参见https://stackoverflow.com/a/6972830和jsFiddle http://jsfiddle.net/JUtcX/2/

If someone performs a Ctrl+F with text from the non-visible lines, the browser reports a match but cannot show it (because it's hidden). 如果某人使用来自不可见行的文本执行Ctrl + F,则浏览器会报告匹配但无法显示(因为它已隐藏)。

How can I react to Ctrl+F and open the container whether a non-visible text in it was searched for? 如何对Ctrl + F作出反应并打开容器是否搜索了其中的不可见文本?

[Update] Approaches that do not meet all requirements: [更新]不符合所有要求的方法:

  1. Listening for Ctrl+F. 听取Ctrl + F.
    • I have multiple containers and only want to expand those containing the search phrase. 我有多个容器,只想扩展包含搜索短语的容器。 Upon listening for Ctrl+FI could only open all containers at once. 在听取Ctrl + FI时,只能一次打开所有容器。
    • Does not work on all systems. 不适用于所有系统。 This is a negligible defect only, though. 但这只是一个可以忽略不计的缺陷。
  2. Chrome-specific workaround ( link ) 特定于Chrome的解决方法( 链接
    • At least also Firefox should be supported 至少还应该支持Firefox

You can do something like this: 你可以这样做:

 function find(e) { if (e.ctrlKey && e.keyCode == 70) { document.getElementById("hide").style.display = "block"; } } document.addEventListener('keyup', find, false); 
 #hide{ display: none; } 
 <div> ASDF: <div id="hide"> Hidden </div> </div> 

I don't think it is possible to listen to those layout modifications. 我认为不可能听那些布局修改。

When the browser find an element, it is equivalent to call scrollIntoView for the matched element. 当浏览器找到一个元素时,它相当于为匹配的元素调用scrollIntoView。 Thus a scroll event will be fired only if the container div is scrollable. 因此,仅当容器div可滚动时才会触发滚动事件。

In the example, the parent style is overflow: hidden;. 在示例中,父样式是overflow:hidden;。 Thus it does not trigger any scroll event. 因此它不会触发任何滚动事件。

It becomes then impossible to listen to these layout change, because the only workaround that exist to listen to scroll event on overflow:hiden element, is to listen to mouse wheel event ... 然后就不可能听到这些布局的变化,因为在overflow:hiden元素上监听滚动事件的唯一解决方法是收听鼠标滚轮事件...

The bad story is that it is then impossible to prevent user from modifying layout through the browser find, because even if one can prevent Ctrl+F or F3, we can't prevent user from using the Edit-> Find menu in Firefox or IE 坏的故事是,因此不可能阻止用户通过浏览器查找修改布局,因为即使可以阻止Ctrl + F或F3,我们也无法阻止用户在Firefox或IE中使用Edit-> Find菜单

JBE JBE

I don't know of any way you can listen for a find-like event and if that's supported in any browser it sure isn't a portable solution. 我不知道你有什么方法可以听取类似发现的事件,如果在任何浏览器中都支持它,那肯定不是一个可移植的解决方案。

I also don't know what you're trying to achieve but I think that your best option is to listen for the keyboard events that trigger the find window and attempt to cancel them while attempting to emulate the find-toolbar/window with JavaScript of your own. 我也不知道你想要实现什么,但我认为你最好的选择是监听触发查找窗口的键盘事件,并尝试在尝试使用JavaScript模拟find-toolbar / window时取消它们。你自己。 This is however a herculean (and nearly impossible) task due to some browsers customization of keyboard shortcuts depending on the localization (for instance, in IE, en-US uses Ctrl+F (for Find) while pt-PT uses Ctrl+L (for Localizar, meaning find)). 然而,由于某些浏览器根据本地化定制键盘快捷键,这是一项艰巨的任务(而且几乎不可能)(例如,在IE中,en-US使用Ctrl + F(用于查找),而pt-PT使用Ctrl + L(对于Localizar,意思是查找))。

Conclusion: I think you're out of luck there... 结论:我认为你在那里运气不好......

Miguel Ventura 米格尔文图拉

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM