我已经尝试了代码in this thread,但它似乎对我不起作用。我使用的是Firefox 15,它适用于Chrome。
这是我的代码:
<!DOCTYPE html>
<head>
<title>A Simple Draggable Object</title>
</head>
<body>
<script>
window.onload=function() {
var dragItems = document.querySelectorAll('[draggable=true]');
for (var i = 0; i < dragItems.length; i++) {
addEvent(dragItems[i], 'dragstart', function (event) {
// store the ID of the element, and collect it on the drop later on
event.dataTransfer.setData('Text', this.id);
});
}
};
</script>
<h1>Test #1: A Simple Draggable Object</h1>
<div draggable="true">This text should be draggable.</div>
</body>
</html>
感谢任何帮助
答案 0 :(得分:2)
window.onload=function() {
var dragItems = document.querySelectorAll('[draggable=true]');
for (var i = 0; i < dragItems.length; i++) {
dragItems[i].addEventListener('dragstart', function (event) {
event.dataTransfer.setData('Text', this.id);
});
}
};
为我工作。感谢Kris C