我的职能如下:
$('#cover-drop-zone')[0].ondrop = function(e) {如何使用上述代码针对两个不同的div?我希望两个div都有ondrop方法。
发布于 2013-09-20 13:53:29
为什么不使用jQuery:
$('#cover-drop-zone, #other-element-id').on('drop', function(e){
// do stuff here
});因为您的问题没有用jquery标记,所以可以使用普通的JavaScript:
var elems = document.querySelectorAll('#cover-drop-zone, #other-element-id');
function dropFunction (e) {
// e is the event (passed automatically as the first parameter,
// this will refer to the element on which the function is called
// and whatever your function would/should do...
}
for (var i = 0, len = elems.length; i < len; i++){
elems[i].addEventListener('drop', dropFunction);
}参考文献:
on()。发布于 2013-09-20 13:54:00
使用此代码:
$('#cover-drop-zone, #div2').bind('ondrop ', function(e) { })https://stackoverflow.com/questions/18918492
复制相似问题