扫码关注官方订阅号
景点
报错:TypeError: ev.preventDefult is not a function
走同样的路,发现不同的人生
TypeError: ev.preventDefult is not a function 意思就是ev.preventDefult写错了。
因为你的字写错了,应该是:
function allowDrop(ev){ ev.preventDefault(); }
你少了a
a
TypeError: ev.preventDefult is not a function 根据错误提示就知道是ev.preventDefult写错了,其实仔细想一下这个提示你应该就恍悟了。改对了就可以拖拽了,已试。
TypeError: ev.preventDefult is not a function
<!DOCTYPE html> <head> <title>test</title> </head> <body> <p id="content"> <p style="width: 100px;height: 100px;background: orange;" id="source"> <p id="touch-source" draggable="true" ondragstart="drag(event)"> <span class="title">景点</span> </p> </p> <p style="width: 100px;height: 100px;background: #ec1611;" id="target" ondrop="drop(event)" ondragover="allowDrop(event)"></p> </p> <script> function drag(ev){ ev.dataTransfer.setData("Text",ev.target.id); }; function allowDrop(ev){ ev.preventDefault(); }; function drop(ev){ ev.preventDefault(); var data = ev.dataTransfer.getData("Text"); ev.target.appendChild(document.getElementById(data)); }; </script> </body>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
TypeError: ev.preventDefult is not a function 意思就是ev.preventDefult写错了。
因为你的字写错了,应该是:
TypeError: ev.preventDefult is not a function根据错误提示就知道是ev.preventDefult写错了,其实仔细想一下这个提示你应该就恍悟了。改对了就可以拖拽了,已试。