如何检查bootstrap模态是否打开,所以我可以使用jquery validate [英] How to check if bootstrap modal is open, so i can use jquery validate

查看:74
本文介绍了如何检查bootstrap模态是否打开,所以我可以使用jquery validate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仅在模式打开时才需要进行验证,因为如果我打开它,然后我将其关闭,并且我按下了打开模式的按钮,则该按钮不起作用,因为它正在进行jquery验证,但未显示,因为该模式已被撤消.

i need to make a validation only if a modal is open, because if i open it, and then i close it, and the i press the button that opens the modal it doesn't work because it is making the jquery validation, but not showing because the modal was dismissed.

因此,如果模式已打开,我想广告一个jQuery,以便我进行验证,这可能吗?

So i want to ad a jquery if modal is open so the i do validate, is this possible?

<script>
$(document).ready(function(){

var validator =$('#form1').validate(
 {
  ignore: "",
  rules: {

usu_login: {
  required: true
},
usu_password: {
  required: true
},
usu_email: {
  required: true
},
usu_nombre1: {
  required: true
},
usu_apellido1: {
  required: true
},
usu_fecha_nac: {
  required: true
},
usu_cedula: {
  required: true
},
usu_telefono1: {
  required: true
},
rol_id: {
  required: true
},
dependencia_id: {
  required: true
},
  },

  highlight: function(element) {
$(element).closest('.grupo').addClass('has-error');
        if($(".tab-content").find("div.tab-pane.active:has(div.has-error)").length == 0)
        {
            $(".tab-content").find("div.tab-pane:hidden:has(div.has-error)").each(function(index, tab)
            {
                var id = $(tab).attr("id");

                $('a[href="#' + id + '"]').tab('show');
            });
        }
  },
  unhighlight: function(element) {
$(element).closest('.grupo').removeClass('has-error');
  }
 });

}); // end document.ready

</script>

推荐答案

为避免@GregPettit提到的竞争条件,可以使用:

To avoid the race condition @GregPettit mentions, one can use:

($("element").data('bs.modal') || {})._isShown    // Bootstrap 4
($("element").data('bs.modal') || {}).isShown     // Bootstrap <= 3

,如 Twitter Bootstrap Modal-IsShown 中所述.

当尚未打开模态时,.data('bs.modal')返回undefined,因此返回|| {}-这将使isShown成为(虚假的)值undefined.如果您严格要求的话,可以做($("element").data('bs.modal') || {isShown: false}).isShown

When the modal is not yet opened, .data('bs.modal') returns undefined, hence the || {} - which will make isShown the (falsy) value undefined. If you're into strictness one could do ($("element").data('bs.modal') || {isShown: false}).isShown

这篇关于如何检查bootstrap模态是否打开,所以我可以使用jquery validate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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