避免在输入按键时关闭模态 [英] Avoid modal dismiss on enter keypress

查看:27
本文介绍了避免在输入按键时关闭模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个带有表单的引导模式,我只是注意到当我按下 Enter 键时,模式被关闭.有没有办法在按 Enter 时不关闭它?

I have set up a bootstrap modal with a form inside it, I just noticed that when I press the Enter key, the modal gets dismissed. Is there a way not to dismiss it when pressing Enter?

我尝试使用 keyboard:false 激活模态,但这只能防止使用 ESC 键解除.

I tried activating the modal with keyboard:false, but that only prevents dismissal with the ESC key.

推荐答案

我也刚遇到这个问题.
我的问题是我的模态中有一个关闭按钮

I just had this problem too.
My problem was that i had a close button in my modal

<button class="close" data-dismiss="modal">&times;</button>

在输入字段中按 Enter 会触发此按钮.我改为将其改为锚点,现在它按预期工作(输入提交表单但不关闭模式).

Pressing enter in the input field caused this button to be fired. I changed it to an anchor instead and it works as expected now (enter submits the form and does not close the modal).

<a class="close" data-dismiss="modal">&times;</a>

没有看到您的消息来源,我无法确认您的原因是否相同.

Without seeing your source, I can't confirm that your cause is the same though.

这篇关于避免在输入按键时关闭模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆