Angular 2(keydown.enter)无法阻止Default() [英] Angular 2 (keydown.enter) can not preventDefault()
本文介绍了Angular 2(keydown.enter)无法阻止Default()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在模板中使用(keydown.enter)
时,event.preventDefault()
不起作用.
这是演示: https://plnkr.co/edit/GZrVt7l6BEO2uHfWFoTQ?p=preview
请帮助我.
the event.preventDefault()
doesn't work when I use (keydown.enter)
in template.
This is demo: https://plnkr.co/edit/GZrVt7l6BEO2uHfWFoTQ?p=preview
Please help me.
推荐答案
因此,在这里留下正确的答案,在这种情况下使用的正确操作是event.stopPropagation()
而不是event.preventDefault()
.
So just to leave a proper answer here, the correct action to use in this case is event.stopPropagation()
rather than event.preventDefault()
.
event.preventDefault()JSFiddle示例
event.stopPropagation()JSFiddle示例
两个示例都对这两种情况进行了简短解释.
Both examples contain a small explanation for whats happening with both.
这篇关于Angular 2(keydown.enter)无法阻止Default()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文