【发布时间】:2015-04-09 03:08:00
【问题描述】:
我遇到了 Chrome 和 Opera 的错误,我想知道它是否已知,如果已知,是否有解决方案?
如果我在 dragstart 事件上更改 DOM,它会立即触发 dragend 事件?!这是一个错误还是背后有什么原因?仅在 Chrome 和 Opera 中发生。 Firefox 有效。
感谢每一个回答。
$('body').on({
dragstart: function(e) {
dragProfilefieldSrcElformid = $(this).attr("data-profilefieldid-formid");
e.dataTransfer = e.originalEvent.dataTransfer;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', $(this).attr("data-profilefieldid"));
// Changing the DOM, fires the dragend Event in Chrome?
$("#plugin_loginlogout_pfcontainer_" + dragProfilefieldSrcElformid).find(".plugin_loginlogout_pf_entryfield").addClass("highlight"); // This doesn't work in Chrome and Opera, but in Firefox
},
dragend: function() {
console.log("dragend");
}
".plugin_loginlogout_pf");
编辑:
将 DOM Change 放入 setTimeout 函数中似乎可以解决问题!
【问题讨论】:
-
有人可以确认这是错误还是正常行为?它似乎也影响了 Firefox。
-
@thelolcat 可能重复stackoverflow.com/a/15114255/2646526? JQuery 文档谈论使用
dragstop,而不是dragend。所以在 jQuery 中没有定义行为来处理dragend。 -
是
$("#plugin_loginlogout_pfcontainer_" + dragProfilefieldSrcElformid)在您拖动的元素内还是在其他地方? -
".plugin_loginlogout_pf"后面的dragend函数是什么?
标签: javascript jquery