dpsr1670 2014-01-25 18:27
浏览 59
已采纳

JQuery函数没有运行

The program below contains various error messages to be displayed under certain conditions. These conditions are found through PHP code, after which the necessary JQuery script is echoed in PHP to make the messages appear.

At first, all messages in the .warning class are hidden. Then, if a certain condition is met, particular ids of this class are shown. Below is the relevant code.

<?php require_once 'connection.php'; ?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Create Account</title>
        <link rel="stylesheet" type="text/css" href="Styles2.css">
        <script src="JQuery.js"></script>
    </head>
    <body>

        <script>

    $(document).ready(function(){

 $('.warning').hide();

 });


    </script>

    <div class="unloggedheadingbar">

    </div>

    <br>

    <div class="createaccount">  

        <center><h1>Create Account</h1></center>

    <center><table>
        <form action="create_account.php" method="post">

         <tr><td><font class="createaccountfont">Email</font></td><td><input type="text" name="Email" placeholder="someone@somewhere.com" value="<?php if(isset($_POST['Create'])){ echo $_POST['Email']; } ?>" class="createaccounttext"></td></tr>
         <tr><td colspan="2"><br></td></tr>
         <tr><td><font class="createaccountfont">Password</font></td><td><input type="password" name="Password" class="createaccounttext"></td></tr>
         <tr><td colspan="2"><br></td></tr>
         <tr><td><font class="createaccountfont">Confirm Password&nbsp;&nbsp;</font></td><td><input type="password" name="ConfirmPassword" class="createaccounttext"></td></tr>

    </table></center>

        <br>

        <center><input type="submit" name="Create" value="Create Account" class="createButton" id="Create"></center>

        </form>

            <br>    

            <div class="warning" id="passwordMatchError">
                <center><font class="warningText">Your password confirmation must match with your original password!</font></center>
            </div>  

            <div class="warning" id="emailFormatError">
                <center><font class="warningText">Your email must match the someone@something.com format.</font></center>
            </div>

            <div class="warning" id="emailDuplicateError">
                <center><font class="warningText">An account under this email already exists.</font></center>
            </div>

        </div>

    <?php

    if(isset($_POST['Create'])){

        $email = $_POST['Email'];
        $password = md5($_POST['Password']);

        if(strpos($email, '@') !== TRUE){

            echo '<script>

                $(".warning").hide();

                $("#emailFormatError").show();

                  </script>';

        }elseif($_POST['Password'] != $_POST['ConfirmPassword']){

            echo '<script>

                $(".warning").hide();

                $("#passwordMatchError").show();

                  </script>';

        }else{

        $query = "SELECT * FROM user_table WHERE Email = '" . $email . "';";
        $result = mysqli_query($con, $query);

        if(mysqli_num_rows($result) == 0){

        $query = "INSERT INTO user_table VALUES ('" . $email . "', '" . $password . "');"; 
        mysqli_query($con, $query);

        }else{

           echo '<script>

                $(".warning").hide();

                $("#emailDuplicateError").show();

                  </script>';

        }

        }
    }

    ?>

</body>

However, the objects with particular IDs are not actually shown. Does anyone know why this may be? Thank you.

  • 写回答

1条回答 默认 最新

  • dsgsgs30201 2014-01-25 18:33
    关注

    jQuery actions should be placed in $( document ).ready( function () {} );, i.e.:

    echo '<script>$( document ).ready( function () {
        $(".warning").hide();
        $("#emailFormatError").show();
    } );</script>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波