简体   繁体   English

如何将windows.alert替换为sweetalert?

[英]How to replace the windows.alert into a sweetalert?

<form class="w3-container" form method="POST" action="login.php" autocomplete="off">
        <div class="w3-section">
            <label><b><i class="fa fa-user"></i> Username</b></label>
            <input class="w3-input w3-border w3-margin-bottom" type="text" placeholder="Enter Username" name="username" required>
            <label><b><i class="fa fa-unlock-alt" id="iconcart"></i> Password</b></label>
            <input class="w3-input w3-border" type="password" placeholder="Enter Password" name="password" required>
            <button class="w3-button w3-block w3-green w3-section w3-padding" type="submit">Login</button>
            <input class="w3-check w3-margin-top" type="checkbox" checked="checked"> Remember me
        </div>
    </form>








 if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $username=check_input($_POST['username']);

        if (!preg_match("/^[a-zA-Z0-9_]*$/",$username)) {
            ?>  
            <script>
                window.alert('Username should not contain space and special characters!');
                window.history.back();
            </script>
        <?php
        }
        else{

        $fusername=$username;

        $password = check_input($_POST["password"]);
        $fpassword=md5($password);

        $query=mysqli_query($conn,"select * from `user` where username='$fusername' and password='$fpassword'");

        if(mysqli_num_rows($query)==0){
            ?>

            <script>
                    window.alert('Login Failed, Invalid Username or Password!');
                    window.history.back();
                </script>
window.alert=function(event) {
    event.preventDefault();
    /* Your Sweetalert code here */  
}

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

相关问题 比较windows.alert中的字符串 - compare string inside windows.alert 柏树中 on('windows.alert()') 和 on('windows:alert') 之间的区别? - Difference between on('windows.alert()') and on('windows:alert') in cypress? 从servlet向jsp发送响应后,如何显示windows.alert(“ msg”)? - how do i show windows.alert(“msg”) after send a response to jsp from servlet? 我们可以在不使用警报或windows.alert的情况下弹出窗口吗 - can we have a pop up without the use of alert or windows.alert Windows.alert() 阻止访问/数据输入到电子反应应用程序中的文本输入字段。 处理 windows.alert 的最佳方法是什么? - Windows.alert() preventing access/data entry into text input field in electron-react app. What is the best way to handle windows.alert? 如何使用sweetalert创建模式警报? - How to create modal alert using sweetalert? 如何在 laravel 中使用 sweetalert 使用问题警报? - How to use question alert using sweetalert in laravel? 我如何使用sweetAlert js在chice上重定向警报按钮? - How can i redirect alert button on chice using sweetAlert js? 将alert()转换为sweetAlert()-javascript - convert alert() to sweetAlert() - javascript 如何使用 sweetalert 在 html 中显示 php 警报消息 - How to display php alert message in html using sweetalert
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM