简体   繁体   English

完全禁用父元素的焦点

[英]Completely disable focus of elements in a parent

Suppose I have a link, which would fade out the entire page when link is clicked. 假设我有一个链接,当单击链接时,它将淡出整个页面。 The reason I fade out the page is because a next page is about to load, but it is not loaded yet. 我淡出该页面的原因是因为下一页即将加载,但尚未加载。 I can use pointer-events: none which will disable any mouse events until the next page is loaded. 我可以使用pointer-events: none会禁用任何鼠标事件,直到加载下一页。

Suppose it was done with the keyboard, I could use the following to prevent double-enter, or to cleanly disable all elements within, for example tab-enter would be disabled this way as well. 假设它是用键盘完成的,我可以使用以下命令防止重复输入,或者彻底禁用其中的所有元素,例如,也可以通过这种方式禁用tab-enter。

parent.onkeydown = fals
parent.onkeyup = fals
parent.onkeypress = fals
function fals() {return false}

This works well for short loads, but if it takes a long time to load, the user may notice the following difficulties. 这对于短载荷效果很好,但如果加载时间较长,则用户可能会注意到以下困难。

  • Cannot tab away from the a tag. 无法在标签旁边远离标签。
  • Cannot use several of the keyboard shortcuts which would control the browser. 无法使用几个可以控制浏览器的键盘快捷键。
  • Able to tab into the disabled area from the address bar. 可以从地址栏进入禁用区域。

Is there a modern and slick way to prevent these 3 problems, other than setting an onfocus=blur for all of the child elements? 除了为所有子元素设置onfocus = blur之外,是否有一种现代且巧妙的方法来防止这三个问题? I do not care about IE today. 我今天不在乎IE。

I think the commonly accepted way of dealing with things like what you're talking about is to use Modal's, which is to say when they click that link, you pop up a box that says 'Processing' or something like that, and you create a fullscreen div with a z-index above everything else so the user can't click / interact with anything else on the screen until you're done doing whatever it is you are doing. 我认为,处理诸如您所谈论的内容之类的公认方法是使用Modal,也就是说,当他们单击该链接时,您会弹出一个框,上面写着“正在处理”或类似内容,然后您创建具有z索引的全屏div,使其在所有其他内容之上,因此用户无法点击或与屏幕上的其他任何内容进行交互,直到您完成所要执行的操作为止。

See http://twitter.github.com/bootstrap/javascript.html#modals for an example of what i'm talking about. 有关我正在谈论的示例,请参见http://twitter.github.com/bootstrap/javascript.html#modals

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

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