99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

HTML事件屬性ondrop

2018-01-05 13:58 更新

HTML事件屬性ondrop


觸發(fā) ondrop 屬性事件當(dāng)在可拖放目標上放置可拖動元素或文本選擇時。

要使元素可拖動,請標記該元素與全局HTML5 draggable 屬性。

默認情況下,鏈接和圖像是可拖動的。

在draggable源元素上觸發(fā)的事件:

  • ondragstart - starting dragging
  • ondrag - during the dragging
  • ondragend - finish dragging

投放目標上觸發(fā)的事件:

  • ondragenter - when the dragged element enters the droppable target
  • ondragover - when the dragged element is over the droppable target
  • ondragleave - when the dragged element leaves the droppable target
  • ondrop - when the dragged element is dropped on the droppable target


HTML5中的新功能

ondrop 屬性是HTML5中的新特性。

句法

<element ondrop="script or Javascript function name">

支持的標簽

所有HTML元素

瀏覽器兼容性

ondrop Yes 9.0 Yes Yes Yes

例子

<!DOCTYPE HTML>
<html>
<head>
<style>
#droptarget {
    float: left; 
    width: 200px; 
    height: 35px;
    margin: 55px;
    margin-top: 155px;
    padding: 10px;
    border: 1px solid black;
}
</style>
</head>
<body>

<p ondragstart="dragStart(event)" draggable="true" id="dragtarget">Drag me into the rectangle!</p>
<div id="droptarget" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<script>
function dragStart(event) {
    event.dataTransfer.setData("Text", event.target.id);
}
function allowDrop(event) {
    event.preventDefault();
    console.log("OVER.");
    
}

function drop(event) {
    event.preventDefault();
    var data = event.dataTransfer.getData("Text");
    event.target.appendChild(document.getElementById(data));
    console.log("dropped.");
}
</script>

</body>
</html>

Click to view the demo



以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號