JavaScript-防止拖放剪切和粘贴
我想防止可满足的DIV上的以下行为,因为如果DIV包含其他任何元素,则与结构混乱。
我尝试了一个明显的:
- 设置draggable =“ false”在div
- 呼叫的dressdefault上的dragstart和drop events(也在div上的事件侦听器)
上,但这似乎不起作用,我想要要定期粘贴,因此禁用这不是一个选择。
任何帮助都将不胜感激。谢谢!
I want to prevent the following behavior on a contenteditable div, because it messes with the structure if the div contains any other elements but text nodes.
I have tried the obvious:
- Setting draggable="false" on the div
- Calling preventDefault on the dragstart and drop events (event listeners also on the div)
However, this does not seem to work and I want to allow regular pasting, so disabling that is not an option.
Any help would be much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预防违规
Ondragover
应防止此行为。https://www.w3schools.com/jsref/jsref/jsref/jsref/event_ondragover.asp
preventDefault
onondragover
should prevent this behaviour.https://www.w3schools.com/jsref/event_ondragover.asp