我在看https://www.w3schools.com/html/html5_draganddrop.asp并且
我想了解为什么ondragstart =“ drag(event)”起作用但为什么“ drag(ev)”不起作用?

`function drag(ev){
  ev.dataTransfer.setData(“ text”,ev.target.id);
}

`

最佳答案

事件属性(例如ondrop =“ drop(event)”)将窗口事件属性传递给该属性中定义的函数。您可以在W3Schools Tryit页面上用window.event替换event,它仍然可以使用,但是如果用ev替换event,则由于未定义windows.ev变量,因此无法使用。 ev是事件处理程序中赋予事件的变量,该变量已传递给事件处理程序。

关于javascript - 理解不同的拖放参数?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57863050/

10-12 00:02