A global event handler dragenter 事件。

句法

var dragenterHandler = targetElement.ondragenter;
					

返回值

dragenterHandler
dragenter event handler for element targetElement .

范例

This example demonstrates using the ondragenter attribute handler to set an element's dragenter event handler.

<!DOCTYPE html>
<html lang=en>
<title>Examples of using the Drag and Drop Global Event Attribute</title>
<meta content="width=device-width">
<style>
  div {
    margin: 0em;
    padding: 2em;
  }
  #source {
    color: blue;
    border: 1px solid black;
  }
  #target {
    border: 1px solid black;
  }
</style>
</head>
<script>
function dragstart_handler(ev) {
 console.log("dragStart");
 // Change the source element's background color to signify drag has started
 ev.currentTarget.style.border = "dashed";
 ev.dataTransfer.setData("text", ev.target.id);
}
function dragover_handler(ev) {
 console.log("dragOver");
 // Change the target element's border to signify a drag over event
 // has occurred
 ev.currentTarget.style.background = "lightblue";
 ev.preventDefault();
}
function drop_handler(ev) {
 console.log("Drop");
 ev.preventDefault();
 var data = ev.dataTransfer.getData("text");
 ev.target.appendChild(document.getElementById(data));
}
function dragenter_handler(ev) {
 console.log("dragEnter");
 // Change the source element's background color for enter events
 ev.currentTarget.style.background = "yellow";
}
function dragleave_handler(ev) {
 console.log("dragLeave");
 // Change the source element's border back to white
 ev.currentTarget.style.background = "white";
}
function dragend_handler(ev) {
 console.log("dragEnd");
 // Change the target element's background color to visually indicate
 // the drag ended.
 var el=document.getElementById("target");
 el.style.background = "pink";
}
function dragexit_handler(ev) {
 console.log("dragExit");
 // Change the source element's border back to green to signify a dragexit event
 ev.currentTarget.style.background = "green";
}
function init() {
 // Set handlers for the source's enter/leave/end/exit events
 var el=document.getElementById("source");
 el.ondragenter = dragenter_handler;
 el.ondragleave = dragleave_handler;
 el.ondragend = dragend_handler;
 el.ondragexit = dragexit_handler;
}
</script>
<body onload="init();">
<h1>Examples of <code>ondragenter</code>, <code>ondragleave</code>, <code>ondragend</code>, <code>ondragexit</code></h1>
 <div>
   <p id="source" ondragstart="dragstart_handler(event);" draggable="true">
     Select this element, drag it to the Drop Zone and then release the selection to move the element.</p>
 </div>
 <div id="target" ondrop="drop_handler(event);" ondragover="dragover_handler(event);">Drop Zone</div>
</body>
</html>
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'ondragenter' in that specification.
实时标准
HTML 5.1
The definition of 'ondragenter' in that specification.
推荐 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ondragenter Chrome 4 Edge 12 Firefox 3.5 IE 10 Opera 12 Safari 3.1 WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改:
  1. GlobalEventHandlers
  2. 特性
    1. onabort
    2. onanimationcancel
    3. onanimationend
    4. onanimationiteration
    5. onauxclick
    6. onblur
    7. oncancel
    8. oncanplay
    9. oncanplaythrough
    10. onchange
    11. onclick
    12. onclose
    13. oncontextmenu
    14. oncuechange
    15. ondblclick
    16. ondurationchange
    17. onended
    18. onerror
    19. onfocus
    20. onformdata
    21. ongotpointercapture
    22. oninput
    23. oninvalid
    24. onkeydown
    25. onkeypress
    26. onkeyup
    27. onload
    28. onloadeddata
    29. onloadedmetadata
    30. onloadend
    31. onloadstart
    32. onlostpointercapture
    33. onmousedown
    34. onmouseenter
    35. onmouseleave
    36. onmousemove
    37. onmouseout
    38. onmouseover
    39. onmouseup
    40. onpause
    41. onplay
    42. onplaying
    43. onpointercancel
    44. onpointerdown
    45. onpointerenter
    46. onpointerleave
    47. onpointermove
    48. onpointerout
    49. onpointerover
    50. onpointerup
    51. onreset
    52. onresize
    53. onscroll
    54. onselect
    55. onselectionchange
    56. onselectstart
    57. onsubmit
    58. ontouchcancel
    59. ontouchstart
    60. ontransitioncancel
    61. ontransitionend
    62. onwheel
  3. 实现通过:
    1. Document
    2. HTMLElement
    3. SVGElement
    4. Window
    5. XULElement
  4. HTML DOM 相关页面
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. HTMLAnchorElement
    5. HTMLAreaElement
    6. HTMLAudioElement
    7. HTMLBRElement
    8. HTMLBaseElement
    9. HTMLBaseFontElement
    10. HTMLBodyElement
    11. HTMLButtonElement
    12. HTMLCanvasElement
    13. HTMLContentElement
    14. HTMLDListElement
    15. HTMLDataElement
    16. HTMLDataListElement
    17. HTMLDialogElement
    18. HTMLDivElement
    19. HTMLDocument
    20. HTMLElement
    21. HTMLEmbedElement
    22. HTMLFieldSetElement
    23. HTMLFormControlsCollection
    24. HTMLFormElement
    25. HTMLFrameSetElement
    26. HTMLHRElement
    27. HTMLHeadElement
    28. HTMLHeadingElement
    29. HTMLHtmlElement
    30. HTMLIFrameElement
    31. HTMLImageElement
    32. HTMLInputElement
    33. HTMLIsIndexElement
    34. HTMLKeygenElement
    35. HTMLLIElement
    36. HTMLLabelElement
    37. HTMLLegendElement
    38. HTMLLinkElement
    39. HTMLMapElement
    40. HTMLMediaElement
    41. HTMLMetaElement
    42. HTMLMeterElement
    43. HTMLModElement
    44. HTMLOListElement
    45. HTMLObjectElement
    46. HTMLOptGroupElement
    47. HTMLOptionElement
    48. HTMLOptionsCollection
    49. HTMLOutputElement
    50. HTMLParagraphElement
    51. HTMLParamElement
    52. HTMLPictureElement
    53. HTMLPreElement
    54. HTMLProgressElement
    55. HTMLQuoteElement
    56. HTMLScriptElement
    57. HTMLSelectElement
    58. HTMLShadowElement
    59. HTMLSourceElement
    60. HTMLSpanElement
    61. HTMLStyleElement
    62. HTMLTableCaptionElement
    63. HTMLTableCellElement
    64. HTMLTableColElement
    65. HTMLTableDataCellElement
    66. HTMLTableElement
    67. HTMLTableHeaderCellElement
    68. HTMLTableRowElement
    69. HTMLTableSectionElement
    70. HTMLTemplateElement
    71. HTMLTextAreaElement
    72. HTMLTimeElement
    73. HTMLTitleElement
    74. HTMLTrackElement
    75. HTMLUListElement
    76. HTMLUnknownElement
    77. HTMLVideoElement
    78. HashChangeEvent
    79. 历史
    80. ImageData
    81. 定位
    82. MessageChannel
    83. MessageEvent
    84. MessagePort
    85. Navigator
    86. NavigatorGeolocation
    87. NavigatorID
    88. NavigatorLanguage
    89. NavigatorOnLine
    90. NavigatorPlugins
    91. PageTransitionEvent
    92. Plugin
    93. PluginArray
    94. PopStateEvent
    95. PortCollection
    96. PromiseRejectionEvent
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers