【问题标题】:Hand Cursor is not working in the firefox browser手形光标在 Firefox 浏览器中不起作用
【发布时间】:2021-12-30 23:39:36
【问题描述】:
<html>

<head>
<title>Question</title>
<script type="text/javascript" >
function MouseOverHand(ID)
{
  var Cursor='hand';
  var ID=ID;
  if (!document.all){ Cursor='pointer'; }
  document.getElementById(ID).style.cursor=Cursor;      
}
</script>
<script type="text/javascript" >
function MouseOverHelp(ID)
{
  var Cursor='help';
  var ID=ID;
  if (!document.all){ Cursor='pointer'; }
  document.getElementById(ID).style.cursor=Cursor;      
}
</script>
</head>

<body>
<label id="Hand" onmouseover="MouseOverHand('Hand');" > Hand </label><br/><br/>
<label id="Help" onmouseover="MouseOverHelp('Help');" > Help </label>
</body>

</html>

上面的 html 用于将鼠标光标置于标签的鼠标上方。在这里,“手”和“帮助”光标在 Internet Explorer 中工作正常,但在 Firefox 和其他浏览器中不工作。

【问题讨论】:

  • 我认为你的意思是将其标记为 javascript(不是 java)
  • 嗯,在这种情况下确实不需要 JavaScript。我建议您使用 CSS 解决方案。
  • @mportiz08:是的,我已经重新标记了 OP。

标签: javascript html firefox mouse-cursor


【解决方案1】:

如果你可以像这样直接指定helphand,则不需要var Cursor

document.getElementById(ID).style.cursor='hand';        

document.getElementById(ID).style.cursor='help';        

请查看working example并查看html源代码

【讨论】:

    【解决方案2】:

    更简单的版本,适用于“所有”浏览器:

    <script type="text/javascript" >
    function MouseOverPointer(obj) //obj is the triggering element
    {
        if(obj.id=='Help')
            obj.style.cursor = "help";
        else if(obj.id=='Hand')
            obj.style.cursor = "pointer";
    }
    </script>
    
    <label id="Hand" onmouseover="MouseOverPointer(this);" > Hand </label><br/><br/>
    <label id="Help" onmouseover="MouseOverPointer(this);" > Help </label>
    

    【讨论】:

      【解决方案3】:

      “手”在 Firefox 中不起作用。试试“pointer”。但是,“帮助”应该可以工作——尝试以比通过 JS 更直接的方式应用样式。

      【讨论】:

        猜你喜欢
        • 2014-10-13
        • 2015-01-06
        • 1970-01-01
        • 2020-04-05
        • 2014-12-09
        • 2021-11-08
        • 1970-01-01
        • 1970-01-01
        • 2017-01-16
        相关资源
        最近更新 更多