event.preventdefault 在 Firefox 中不起作用
event.preventdefault is not working in firefox
我正在尝试将输入中的部分文本设置为只读,以实现我找到了这段代码,但它在 FIrefox 中不起作用,在 chrome 中工作正常。
发现 event.preventDefault 导致问题。尝试返回假,这也不起作用。
角度 JS 指令代码
app.directive('partialReadonly', function () {
return {
restrict: 'A',
link: function ($scope, $element, attrs) {
$element.on('keypress, keydown', function (event) {
var readOnlyLength = attrs["partialReadonly"].length;
if ((event.which != 37 && (event.which != 39))
&& (($element[0].selectionStart < readOnlyLength)
|| (($element[0].selectionStart == readOnlyLength) && (event.which == 8)))) {
alert('preventdef');
//return false;
event.preventDefault();
}
});
$scope.load = function () {
alert('load called attrs["partialReadonly"] ' + attrs["partialReadonly"]);
$scope.temp = attrs["partialReadonly"];
// $element[0].value = attrs["partialReadonly"];
};
}
};
});
网页代码
<input type="text" ng-init="load()" ng-model="key" partial-readonly="{{number}}" />
由于
@epascarello和@Alon不使用警报进行调试,而是使用控制台日志,因此从脚本中删除警报可能会有所帮助。
希望我有帮助
相关文章:
- 为什么javascript:void(0)在Firefox中不起作用
- jpm的默认Firefox路径没有'不起作用
- 设置 CSS 背景在 Firefox 中不起作用
- document.getElementById 在 Firefox 中不起作用
- firefox中的CSS动画不起作用
- event.stopPropagation()在firefox javascript中不起作用
- 复选框.onClick在firefox中不起作用
- window.close();在Chrome和Firefox中不起作用
- JQuery在Chrome中不起作用,但Firefox很好
- 选择“行在 Chrome 和 Firefox 中不起作用(生成的代码)”
- Javascript 按键事件在 Firefox 中不起作用
- window.dispatchEvent 在 Firefox、Safari 或 IE 中不起作用
- 更改 Angular 2 中选择的事件在 Firefox 和 Edge 中不起作用
- jQuery SlideToggle() 在 FireFox 中不起作用,在 Chrome 中工作
- 动态关键帧插入在 IE 或 Firefox 上不起作用
- 使用 nameProp 的 JQuery 图像滚动更新在 Firefox 和 Chrome 中不起作用
- Javascript键码在Firefox中不起作用,但在chrome中运行良好
- HTML5<视频>元素在Firefox、Opera和Safari中不起作用
- 输入类型的图像在Internet Explorer中不起作用,但在Chrome和Firefox中起作用
- Ajax 提交表单不起作用 Firefox