当元素在HTML中被拖动到有效的放置目标时,ondragenter 属性会触发。
<!DOCTYPE HTML> <html> <head> <style type = "text/css"> #BoxA, #BoxB { float:left;padding:10px;margin:10px; -moz-user-select:none; } #BoxA { background-color: #6633FF; width:75px; height:75px; } #BoxB { background-color: #FF6699; width:150px; height:150px; } </style> <script type = "text/javascript"> function dragStart(ev) { ev.dataTransfer.effectAllowed = 'move'; ev.dataTransfer.setData("Text", ev.target.getAttribute('id')); ev.dataTransfer.setDragImage(ev.target,0,0); return true; } </script> </head> <body> <center> <h2>Drag and drop HTML5 demo</h2> <div>Try to drag the purple Box around.</div> <div id = "BoxA" draggable = "true" ondragstart = "return dragStart(ev)"> <p>Drag Me</p> </div> <div id = "BoxB">Dustbin</div> </center> </body> </html>
以上就是当一个元素被拖拽到一个有效的放置目标时,执行一个脚本在HTML中的详细内容,更多请关注编程之家其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。