<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 检查是否有悬停(不设置鼠标悬停/移出)

      pure javascript to check if something has hover (without setting on mouseover/out)(纯 javascript 检查是否有悬停(不设置鼠标悬停/移出))

      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 检查是否有悬停(不设置鼠标悬停/移出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                  <tbody id='wCvXl'></tbody>

                • <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>

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