在内部单击时,防止materializecss下拉菜单关闭 [英] Prevent materializecss dropdown to close when clicking inside it

查看:58
本文介绍了在内部单击时,防止materializecss下拉菜单关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为当前项目使用Materialize.css,并且其中包含一些输入形式的下拉菜单.

I am using Materialize.css for current project, and I have dropdown with some input forms inside it.

Dropdown可以选择关闭方式:

Dropdown has option to close by:

  • .dropdown-content
  • 之外单击
  • .dropdown-content
  • 内单击
  • 点击.下拉按钮

我需要的是在其内部单击时不关闭,因为我需要能够填写输入表单和其他操作.

What I need is to not close when clicking inside of it, because i need to be able to fill in input forms and other actions.

这很简单示例

推荐答案

快速解决方案是单击内容包装器后停止传播.

Quick solution would be to stopPropagation on click on content wrapper.

$('.dropdown-button + .dropdown-content').on('click', function(event) {
  event.stopPropagation();
});

对于该特定用例,我将避免使用下拉列表".但是,如果您要坚持下去,只需应用上面的代码段即可.

I would avoid using 'dropdown' for this particular use-case. But if you want to stick to it just apply the snippet above.

这篇关于在内部单击时,防止materializecss下拉菜单关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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