2

随着 AngularJS 1.2.0-rc.3 的发布,我在搞乱ngCutngCopyngPaste,但我无法取消它们。我认为规范不允许这样做,但确实如此。它必须是可能的......通过搜索也无法真正找到任何东西(只是取消传播)。有任何想法吗?

http://jsfiddle.net/XEEpv/

4

2 回答 2

4

Not sure what you mean exactly by "cancel event" but what you can do with events is:

  • preventDefault() so the default action that this event is normally triggering doesn't take place
  • stopPropagation() so the event doesn't buble up in the DOM herarchy

I presume that you wanted to cancel default action, that is, call preventDefault() on the event:

$scope.cut = function ($event) {
    console.log('cut', $event);
    $event.preventDefault();
}

jsFiddle here: http://jsfiddle.net/M5jRW/

于 2013-10-15T17:44:54.027 回答
1

You can set $event.returnValue to false:

function x($scope) {
    $scope.cut = function ($event) {
        $event.returnValue = false;
        console.log('cut', $event);
    }
    $scope.kp = function ($event) {
        console.log('keypress', $event);
        return false;
    }
}

Here's your updated fiddle: http://jsfiddle.net/XEEpv/1/

于 2013-10-15T17:44:29.340 回答