draggable

draggable 全局属性enumerated 属性,指示元素是否可以通过原生浏览器行为或 HTML 拖放 API 进行拖动。

¥The draggable global attribute is an enumerated attribute that indicates whether the element can be dragged, either with native browser behavior or the HTML Drag and Drop API.

draggable 属性可以应用于严格属于 HTML 命名空间 的元素,这意味着它不能应用于 SVGs。有关命名空间声明的外观及其用途的更多信息,请参阅 命名空间速成课程

¥The draggable attribute may be applied to elements that strictly fall under the HTML namespace, which means that it cannot be applied to SVGs. For more information about what namespace declarations look like, and what they do, see Namespace crash course.

draggable 可以具有以下值:

¥draggable can have the following values:

  • true:元素可以被拖动。
  • false:无法拖动该元素。

警告:该属性是 enumerated,而不是布尔值。值 truefalse 是强制的,并且禁止使用像 <img draggable> 这样的简写。正确的用法是 <img draggable="false">

¥Warning: This attribute is enumerated and not Boolean. A value of true or false is mandatory, and shorthand like <img draggable> is forbidden. The correct usage is <img draggable="false">.

如果未设置该属性,则其默认值为 auto,这意味着拖动行为是默认的浏览器行为:只能拖动文本选择、图片和链接。对于其他元素,必须设置事件 ondragstart 才能进行拖放操作,如本 综合例子 所示。

¥If this attribute is not set, its default value is auto, which means drag behavior is the default browser behavior: only text selections, images, and links can be dragged. For other elements, the event ondragstart must be set for drag and drop to work, as shown in this comprehensive example.

规范

Specification
HTML Standard
# the-draggable-attribute

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also