使用Jquery控制表单在div中提交操作

时间:2012-05-12 16:18:13

标签: jquery forms html fadein fadeout

我试图在我的网站中加载一个具有淡化效果的div中的所有内容,我已经创建了一个jquery函数来处理div中的所有点击事件,例如链接,按钮和表单提交。一切正常,除了表单提交,例如我在我的一个页面中有这个表单:

<form name="form" method="post" action="">
                <p>Enter a Start date for review <font color="red"><b>(mm/dd/yyyy)</b></font>
                    :
                    <input type="text" name="StartDate" id="startDate" maxlength="10" size="15">
                    <br /> <label id="label1" style="color: red"></label>
                <p>Enter a deadline for review <font color="red"><b>(mm/dd/yyyy)</b></font>
                    :
                    <input type="text" name="txtDate" id="txtDate" maxlength="10" size="15">
                    <br /> <label id="label2" style="color: red"></label>
                </p>
                </br>
                </br>
                </br>
                <input type ="submit" name="submitCrit" value="submit"></input></br>
            </form>
            <?php
            if (isset($_POST['txtDate']) && isset($_POST['StartDate'])) { // checking if values passed
                $todays_date = date("m/d/Y"); // getting today's date to check with it
                $today = strtotime($todays_date); // parsing it to timestamp
                $to = date('Y-m-d', str_replace('-', '/', $today)); // replacing / with -
                $date = strtotime($_POST['txtDate']); // parsing enddate to timestamp
                $newdate = date('Y-m-d', str_replace('-', '/', $date)); // replacing / with -
                $startdate = strtotime($_POST['StartDate']); // parsing startdate to timestamp
                $startnewdate = date('Y-m-d', str_replace('-', '/', $startdate)); // replacing / with -
                if ($newdate != null && $newdate > $to
                        && $startnewdate != null && $startnewdate < $newdate
                        && $startnewdate > $to) {
                    $con = mysql_connect('localhost', 'root', ""); //db connection
                    if (!$con) {
                        die('connection error');
                    } else {
                        mysql_select_db("mydb", $con);
                        $query = "
                        UPDATE conference
                        SET rev_startDate = '{$startnewdate}', rev_endDate = '{$newdate}'
                        WHERE conference_id = {$confID}
                        ";
                        echo '<script type="text/javascript">'
                        , 'ChangeText("deadline set successfuly");'
                        , '</script>';

                        if (!mysql_query($query, $con)) {
                            echo "query not run";
                        }
                        mysql_close($con);
                    }
                } else {
                    echo '<script type="text/javascript">'
                    , 'ChangeText("invalid deadline");'
                    , '</script>';
                }
            }
            ?>

这个处理点击事件的函数:

$(document).ready(function() {
               $('#mydiv').delegate('form', 'submit', function() {
                    var page = $(this).attr('action');
                    if (page == "") {
                        return true;
                    }
                    else {
                    $('#mydiv').fadeOut('slow',function() {
                    $('#mydiv').load(page, function () {
                        $(this).fadeIn('slow');
                });
                });
                return false;
                    }
          });
          return false;
          });

然而,当我点击提交时,只有空白页面被加载到div&amp; php脚本不起作用,并且网站中的所有其他表单也会出现同样的问题。谁知道问题出在哪里?

0 个答案:

没有答案