概述`inert` 属性使元素及其后代不可聚焦且不可交互,并从可访问性树移除。常用于模态打开时禁用背景区域。用法/示例<main inert>...</main> <dialog open>...</dialog> const main = document.querySelector('main') const dlg = document.querySelector('dialog') dlg.addEventListener('close', () => { main.inert = false }) 工程建议与 `dialog` 与焦点管理协作,确保打开/关闭时状态一致。在不支持环境通过 polyfill 提供行为,并避免使用 `display: none` 破坏语义。配合 `aria-hidden` 与可见焦点样式提升无障碍质量。参考与验证MDN:`inert` — https://developer.mozilla.org/docs/Web/HTML/Global_attributes/inertweb.dev:Inert — https://web.dev/articles/inert

发表评论 取消回复