【发布时间】:2019-04-17 07:50:36
【问题描述】:
我目前正在开发一个内容可编辑的div。它目前具有允许您拖动文本的默认行为。
Chrome/Windows(目前我测试的唯一环境)。
如何禁用它?制作了一个简单的 sn-p 用于下面的测试:
#root {
border: 1px solid silver;
white-space: pre-wrap;
}
<p>Try selecting a piece of test and drag it around the editable area</p>
<div id="root" contenteditable>Hello World
This is a contenteditable
DIV!
</div>
【问题讨论】:
-
我的猜测:你不能。但我的第一个问题是:为什么?
-
@ChrisG 我正在构建一个评论框,我不希望用户四处移动。才发现有可能。只需收听
ondragstart()事件并使用event.preventDefault()取消它
标签: javascript html