MDN、规范和我在 Google 上可以找到的每个站点都说所有 HTML 元素都可以拖动。但是,在实践中我发现我无法拖动文本输入或文本区域,即使它们被禁用也是如此。
例如,使用以下代码:
<img src="http://www.placehold.it/350x150" draggable alt="Placeholder image">
<a href="http://example.com" draggable>Link</a>
<input type="text" draggable>
<input type="text" disabled draggable>
我可以拖动图像和链接,但两个输入都不能拖动。
这是一个 JSfiddle
是否可以使用 HTML5 的 draggable 属性来拖动输入?如果没有,是否有我可以使用的解决方法?
最佳答案
MDN 确认 draggable
is a global attribute (即可以应用于任何元素),但具有以下使用说明:
By default, only text selections, images, and links can be dragged. For all others elements, the event
ondragstart
must be set in order to the drag and drop mechanism to work, as shown in this comprehensive example.
关于javascript - 输入和文本区域可以拖动吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22584201/