event.preventDefault在Android 4.4.4中不起作用

event.preventDefault在Android 4.4.4中不起作用,android,keydown,Android,Keydown,在Android 4.4.4上,当试图阻止在密码字段(input type=“password”无空格)中输入空格键时,它不会阻止按键。在安卓4.4.2中,它运行良好。我还在4.4.2(和设备)上使用emulator也尝试了同样的方法,而且效果也不错 element.bind("keydown", function(e){ if (e.keyCode === 32 ){ e.preventDefault(); e.stopPropagation();

在Android 4.4.4上,当试图阻止在密码字段(input type=“password”无空格)中输入空格键时,它不会阻止按键。在安卓4.4.2中,它运行良好。我还在4.4.2(和设备)上使用emulator也尝试了同样的方法,而且效果也不错

    element.bind("keydown", function(e){
     if (e.keyCode === 32 ){
     e.preventDefault();
     e.stopPropagation();
    }

这是4.4.4中的错误吗?如何解决这个问题呢?

我之前的回答错了,所以我只解释一下实现它的一种方法,这可能会奏效

<input type="text" ng-keydown="disableSpaces($event)">
<script>
    function ctrl($scope){
        $scope.disableSpaces = function($event){
            if($event.keyCode === 32) $event.preventDefault();
        }
    }
</script>

函数ctrl($scope){
$scope.disableSpaces=函数($event){
如果($event.keyCode==32)$event.preventDefault();
}
}

干杯

谢谢,我会试试这个,但我看不出有什么区别,除非你使用的是ng keydown事件,我正在指令中执行。。你能解释一下吗?我不知道它是否会起作用,但是ng-whater指令有样板代码,所以我们不必实现它。如果您退回到通过指令手动绑定事件,则必须自己实现该样板文件。也许,只是也许ng keydown事件中有某种东西可以使它工作,即使您的代码实际上是正确的。