简体   繁体   English

如何使用javascript终止动作

[英]how to terminate actions using javascript

In my image puzzle that I'm attempting to get working, I want to move the mouse cursor to a specific place if the puzzle validation fails. 在我尝试开始工作的图像拼图中,如果拼图验证失败,我想将鼠标光标移到特定位置。 I've made some JavaScript code to be called when the mouse is dragged and dropped. 拖放鼠标时,我已经编写了一些JavaScript代码。 Is there any way to cancel this mouse movement? 有什么办法可以取消这种鼠标移动? Here's the relevant part of my code: 这是我的代码的相关部分:

else if (temp == 9 && validate == false) {
    if (vl == 6 || vl == 8 || vl == 9) {
        var theData = theEvent.dataTransfer.getData("Text");
        var theDraggedElement = document.getElementById(theData);
        theEvent.target.appendChild(theDraggedElement);
        theEvent.preventDefault();
        temp = vl;
    } else {
        alert("invalied move..");
    }
}

There isnt a single command if you want to support multiple browsers unfortunately. 如果您想支持多个浏览器,则没有单个命令。 Try the following: 请尝试以下操作:

if (!e){
  e = window.event;
}
e.stopPropagation();
e.cancelBubble = true;

the if (!e) line checks to see if e is set, as some browsers don't pass the event argument to the method. if (!e)行检查是否设置了e,因为某些浏览器没有将event参数传递给该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM