<small id='1iBr8'></small><noframes id='1iBr8'>

  1. <i id='1iBr8'><tr id='1iBr8'><dt id='1iBr8'><q id='1iBr8'><span id='1iBr8'><b id='1iBr8'><form id='1iBr8'><ins id='1iBr8'></ins><ul id='1iBr8'></ul><sub id='1iBr8'></sub></form><legend id='1iBr8'></legend><bdo id='1iBr8'><pre id='1iBr8'><center id='1iBr8'></center></pre></bdo></b><th id='1iBr8'></th></span></q></dt></tr></i><div id='1iBr8'><tfoot id='1iBr8'></tfoot><dl id='1iBr8'><fieldset id='1iBr8'></fieldset></dl></div>
    <tfoot id='1iBr8'></tfoot>
    <legend id='1iBr8'><style id='1iBr8'><dir id='1iBr8'><q id='1iBr8'></q></dir></style></legend>

        <bdo id='1iBr8'></bdo><ul id='1iBr8'></ul>

      纯 javascript 检查是否有悬停(不设置鼠标悬停/移出)

      时间:2023-11-01

      1. <legend id='L1j6F'><style id='L1j6F'><dir id='L1j6F'><q id='L1j6F'></q></dir></style></legend>

          <tbody id='L1j6F'></tbody>
            <bdo id='L1j6F'></bdo><ul id='L1j6F'></ul>

                <small id='L1j6F'></small><noframes id='L1j6F'>

              1. <i id='L1j6F'><tr id='L1j6F'><dt id='L1j6F'><q id='L1j6F'><span id='L1j6F'><b id='L1j6F'><form id='L1j6F'><ins id='L1j6F'></ins><ul id='L1j6F'></ul><sub id='L1j6F'></sub></form><legend id='L1j6F'></legend><bdo id='L1j6F'><pre id='L1j6F'><center id='L1j6F'></center></pre></bdo></b><th id='L1j6F'></th></span></q></dt></tr></i><div id='L1j6F'><tfoot id='L1j6F'></tfoot><dl id='L1j6F'><fieldset id='L1j6F'></fieldset></dl></div>
                <tfoot id='L1j6F'></tfoot>
                本文介绍了纯 javascript 检查是否有悬停(不设置鼠标悬停/移出)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我见过这个 jQuery 语法:

                I have seen this jQuery syntax:

                if($(element).is(':hover')) { do something}
                

                由于我没有使用 jQuery,我正在寻找用纯 javascript 执行此操作的最佳方法.

                Since I am not using jQuery, I am looking for the best way to do this in pure javascript.

                我知道我可以保留一个全局变量并使用 mouseovermouseout 设置/取消设置它,但我想知道是否有某种方法可以检查元素的本机而是通过 DOM 属性?也许是这样的:

                I know I could keep a global variable and set/unset it using mouseover and mouseout, but I'm wondering if there is some way to inspect the element's native properties via the DOM instead? Maybe something like this:

                if(element.style.className.hovered === true) {do something}
                

                另外,它必须是跨浏览器兼容的.

                Also, it must be cross browser compatible.

                推荐答案

                简单地使用 element.matches(':hover') 对我来说似乎效果很好,你可以使用一个综合的 polyfill浏览器也是:https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

                Simply using element.matches(':hover') seems to work well for me, you can use a comprehensive polyfill for older browsers too: https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

                这篇关于纯 javascript 检查是否有悬停(不设置鼠标悬停/移出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:悬停效果不适用于 IE8 下一篇:jQuery:从另一个元素触发悬停事件

                相关文章

                • <bdo id='wCvXl'></bdo><ul id='wCvXl'></ul>
                <legend id='wCvXl'><style id='wCvXl'><dir id='wCvXl'><q id='wCvXl'></q></dir></style></legend>
                1. <tfoot id='wCvXl'></tfoot>

                  <i id='wCvXl'><tr id='wCvXl'><dt id='wCvXl'><q id='wCvXl'><span id='wCvXl'><b id='wCvXl'><form id='wCvXl'><ins id='wCvXl'></ins><ul id='wCvXl'></ul><sub id='wCvXl'></sub></form><legend id='wCvXl'></legend><bdo id='wCvXl'><pre id='wCvXl'><center id='wCvXl'></center></pre></bdo></b><th id='wCvXl'></th></span></q></dt></tr></i><div id='wCvXl'><tfoot id='wCvXl'></tfoot><dl id='wCvXl'><fieldset id='wCvXl'></fieldset></dl></div>
                2. <small id='wCvXl'></small><noframes id='wCvXl'>