我有一个问题,angular指令不阻止默认的chrome操作。
这是我的指令
app.directive('fileDrag', function () {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem.bind('drop', function(e){
e.preventDefault();
console.log(e);
return false;
});
}
};
});
我的html
<div style="width: 500px; height:500px; background-color: red;" file-drag></div>
当拖到元素上时,我似乎无法让Chrome在新选项卡中不加载图像。什么好主意吗?
您还应该在dragover
事件上preventDefault
,因此将代码更改为:
app.directive('fileDrag', function () {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem.bind('drop', function(e){
e.preventDefault();
console.log(e);
return false;
});
elem.bind('dragover', function(e){
e.preventDefault();
});
}
};
});