【问题标题】:In Meteor, getData('text') always returns an empty string在 Meteor 中,getData('text') 总是返回一个空字符串
【发布时间】:2013-01-31 03:23:23
【问题描述】:

我正在使用 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')); 总是返回一个空字符串..

有人知道为什么吗?

【问题讨论】:

    标签: javascript html events drag-and-drop meteor


    【解决方案1】:

    如果您使用的是 webkit 浏览器 (Safari/Chrome),'drag .liTodos' 下的部分将不适用于所有浏览器。例如,Chrome 将其限制为仅返回 drop 下的数据,具体取决于您拥有的版本。你可以看看这个也看过这个的替代问题

    HTML5 Drag and Drop getData() only works on drop event in Chrome?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 2016-12-16
      • 2019-07-25
      相关资源
      最近更新 更多