1
我想在拖放事件處理程序中獲取拖動元素的ID javascript。如何在javascript中獲取拖動元素的id?
div與id place5是可拖動的,拖放位置是另一個ID爲dropArea的div。
在drop事件處理程序中如何獲取div(place5)的id?
<html>
<head>
<style>
.mainArea{
width: 500px;
height : 500px;
border-color:red;
border-style:solid;
border-width:5px;
}
</style>
<script>
function dragEventHandler(theEvent) {
theEvent.dataTransfer.setData("Text", theEvent.target.id);
//Some code here.
}
function dropEventHandler(theEvent) {
//how to get the id of div with id "place5" here?
}
</script>
</head>
<body>
<div id="dropArea" class="mainArea" ondrop="dropEventHandler(event);" ondragover="event.preventDefault();>
</div>
<div id="place5" draggable="true" ondragstart="dragEventHandler(event);">
</div>
</body>
</html>
你嘗試過這麼遠嗎?請使用您現在嘗試使用的代碼編輯您的問題。 –
可能重複的[我如何得到一個拖曳的元素和綁定時,Id的滴ID?](http://stackoverflow.com/questions/13139681/how-can-i-get-the-id-of-an- drag-element-and-bind-while-dropping) – itsazzad
var draggedID = ui.draggable.attr('id'); – itsazzad