使用导航菜单“组件”- 查看了一些示例,其中许多示例使用 Controller /javascript 动态添加 .current(类似事件的类)。例如:https://www.google.com/analytics/导航栏就是这样做的。一直认为浏览器会为您做到这一点。我想可能是元素有限但是MDN docs说不。
:active CSS pseudo-class matches when an element is being activated by the user. It allows the page to give a feedback that the activation has been detected by the browser. It is frequently used on
<a>
and<button>
HTML elements, but may not be limited to just those.
伪类与类:另一个区别是它添加了伪类与标准类。但不确定仅取决于伪类的限制在哪里。
现在我依靠 psuedo 类和浏览器添加它来工作。即主导航 a:active、a:focus 等,但假设某些事情需要我更改/返工。
最佳答案
快速的回答是浏览器会自动生成 <a>
, <button>
, <select>
, 和 <input>
单击时元素处于事件状态,但导航选项卡和菜单等其他元素需要 Controller 或 jQuery 插件才能在单击时将这些元素设置为事件状态。导航选项卡、日期选择器、菜单等都需要 Controller 在选择时设置事件类。
关于javascript - 什么场景写一个脚本来动态地添加一个.current(active-like class)到一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34703974/