简体   繁体   English

使用w3.css自动打开模态

[英]auto open modal with w3.css

So i am trying to open my modal when a password/username is entered wrong. 所以我试图在输入错误的密码/用户名时打开我的模式。 I have searched google but i can't come up with a good solution on how to do this with W3.CSS . 我已经搜索过google,但是我无法提出关于如何使用W3.CSS的好的解决方案。 My modal is being opened by an ID called "id01" and then i tried a small javascript that i found on stackoverflow in : Open modal with # in url . 我的模态由一个名为"id01"ID打开,然后我尝试了一个在stackoverflow上发现的小型javascript: 使用url中的#打开模态 After trying to edit it with the help of W3.CSS to : 尝试在W3.CSS的帮助下将其编辑为:

function popModal() {
    modal.style.display = "block";
}

var hash = window.location.hash;
if (hash.substring(1) == 'id01') {
    popModal();
}

It still didn't work. 仍然没有用。 So to make a long story short. 长话短说。 How do i make the modal go open when there is like : "#1234" in the url? 当网址中出现"#1234"时,如何打开模式?

Try this: 尝试这个:

            $( document ).ready(function() {
                //console.log( window.location.href );

                if(window.location.href.indexOf("#1234") > -1) {
                    alert("your url contains #1234");
                    popModal();
                }



            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM