2

Jquery 在 Internet Explorer 上不起作用。但是它在其他网络浏览器上运行。我写的代码是

<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#myform").validate({
            debug: false,
            rules: {
                name: "required",
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                name: "Please let us know who you are.",
                email: "A valid email will help us get in touch with you.",
            },
            submitHandler: function(form)
            {
                $.post('process.php', $("#myform").serialize(), function(data)
                {
                    $('#results').html(data);
                });
            }
        });
    });
    </script>

</head>
<body>
<form name="myform" id="myform" action="" method="POST">
    <label for="name" id="name_label">Name</label>
    <input type="text" name="name" id="name" size="30" value=""/>
    <br>
    <label for="email" id="email_label">Email</label>
    <input type="text" name="email" id="email" size="30" value=""/>
    <br>
    <input type="submit" name="submit" value="Submit">
</form>
<div id="results"><div>
</body>
</html>

进程.php

<?php
    print "Form submitted successfully: <br>Your name is <b>".$_POST['name']."</b> and your email is <b>".$_POST['email']."</b><br>";
?>

如何在 INTERNET EXPLORER 上运行此代码。非常感谢您提供任何帮助

4

4 回答 4

2

在此行之后删除“,”

email: "A valid email will help us get in touch with you.",

应该

 email: "A valid email will help us get in touch with you."

在您的消息块中是这样的

 messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",   // <<<< HERE REMOVE IT                
        },

您需要删除最后一行中的“,”(逗号),不需要它。

于 2012-07-05T10:00:41.550 回答
0

试试下面的代码: -

<script type="text/javascript">
  $(document).ready(function(){
    $("#myform").validate({
        debug: false,
        rules: {
            name: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",
        },
        submitHandler: function(form)
        {
            $.post('process.php', $("#myform").serialize(), function(data)
            {
                $('#results').html(data);
            });
            return false;
        }
    });
});
</script>
于 2012-07-05T09:50:17.997 回答
0

我试图在最后执行你的代码。请在顶部添加文档类型。我使用了相同的方法,并且它在早期不起作用时起作用。

<!DOCTYPE html>

谢谢

于 2012-07-05T09:52:10.560 回答
0

你应该添加return falsesubmitHandler.

或者,您可以将提交输入转换为不使用提交表单的按钮<button>Submit</button>

于 2012-07-05T09:49:14.523 回答