我正在使用 Meteor,并且我有以下代码来拖放元素:
Template.occupations.events({
'dragover .liOccupation': function (evt) {
evt.preventDefault();
},
'dragleave .liOccupation': function (evt) {
evt.preventDefault();
},
'drop .liOccupation': function (evt) {
evt.preventDefault();
console.log(evt.dataTransfer.getData('text/plain'));
}
});
Template.todos.events({
'drag .liTodos': function (evt) {
evt.preventDefault();
evt.dataTransfer.setData('text/plain','the');
console.log(evt.dataTransfer.getData('text/plain'));
}
});
发生的情况是 console.log(evt.dataTransfer.getData('text/plain'));
始终返回空字符串..
有人知道为什么吗?
最佳答案
如果您使用的是 webkit 浏览器 (Safari/Chrome),'drag .liTodos'
下的部分不适用于所有浏览器。例如,Chrome 限制它仅在 drop
下返回数据,具体取决于您拥有的版本。你可以看看这个替代问题,它也看过这个
HTML5 Drag and Drop getData() only works on drop event in Chrome?
关于javascript - 在 Meteor 中, getData ('text' ) 总是返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617910/