Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拖放时更改鼠标光标_Javascript_Dom_Mouse Cursor - Fatal编程技术网

Javascript 拖放时更改鼠标光标

Javascript 拖放时更改鼠标光标,javascript,dom,mouse-cursor,Javascript,Dom,Mouse Cursor,我有一个DOM元素,我想将“items”放入其中。我想通过改变光标图标给用户视觉反馈。但是,当按下鼠标按钮时,光标不会改变。如果我不按任何键移动鼠标,它就会改变。但当我按下按钮时就不会了。为什么?如何为用户实现所需的光标反馈?我在用谷歌浏览器 <html> <head> <script type="text/javascript"> function Document()

我有一个DOM元素,我想将“items”放入其中。我想通过改变光标图标给用户视觉反馈。但是,当按下鼠标按钮时,光标不会改变。如果我不按任何键移动鼠标,它就会改变。但当我按下按钮时就不会了。为什么?如何为用户实现所需的光标反馈?我在用谷歌浏览器

<html>
    <head>      
        <script type="text/javascript">         
            function Document()
            {
                var that = document.createElement("div");
                that.style.backgroundColor = "#80ff80";
                that.style.border = "1px solid black";
                that.style.height = "90%";
                that.style.width = "50%";
                that.onmousemove = function (event)
                {
                    //console.log(event.offsetX + ", " + event.offsetY);
                    if (Math.random() < 0.5)
                        that.style.cursor = "not-allowed";
                    else
                        that.style.cursor = "move";
                    return false;
                }
                return that;
            }

            function onLoadPage()
            {
                var doc = new Document();
                document.body.appendChild(doc);
            }

        </script>
    </head>
    <body onload="onLoadPage()" />
</html>

功能文档()
{
var=document.createElement(“div”);
that.style.backgroundColor=“#80ff80”;
that.style.border=“1px纯黑”;
即.style.height=“90%”;
即.style.width=“50%”;
that.onmousemove=函数(事件)
{
//日志(event.offsetX+“,”+event.offsetY);
if(Math.random()<0.5)
that.style.cursor=“不允许”;
其他的
that.style.cursor=“move”;
返回false;
}
归还;
}
函数onLoadPage()
{
var doc=新文档();
document.body.appendChild(doc);
}
1) 将鼠标移到div上。它将随机更改光标图标。
2) 按下鼠标按钮并将鼠标移到div上。它将保留最后一个图标,直到您松开鼠标按钮

编辑:

Chrome的控制台可能会产生这个问题。当我隐藏“开发人员工具”时,光标更改似乎工作得很好。当我启用“开发工具”时,将选项卡更改为任意选项卡并返回,按住鼠标按钮时光标不会更改。

我无法重现您的问题,但我遇到了以下链接,该链接还表明除firefox之外的所有浏览器中都存在错误。这是一个旧链接,但可能会有所帮助


是否将新创建的元素附加到DOM中?当然可以。绿色风格是看它在哪里,然后尝试。我解决了这个问题….?好的。Firefox似乎没有这个问题。我和Chrome一起工作。@Teemu谢谢你的时间。我想是开发工具产生了这个问题,请参见编辑。