-2

我已经尝试了所有我能想到的让这个“发送”按钮工作的方法,但我不太擅长 javascript :(

http://www.kimscakes.biz/contactme.php

Prehaps 有人在这里可以告诉我我要去哪里错了吗?

非常感谢

宝石

4

1 回答 1

3

您在元素存在之前绑定提交,将代码移动到表单之后或将其放入$(document).ready

jQuery(document).ready(function () {
    jQuery("#submit").click(function () {
        console.log("button clicked");
        // declare these vars
        var name = jQuery("#name");
        var email = jQuery("#email");
        var message = jQuery("#message");
        var human = jQuery("#human");
        var success = jQuery("#success");
        var error = jQuery("#error");
        // reset these vars
        success.html("");
        error.html("");
        // ajax call to script.php
        jQuery.getJSON("mailer.php", {
            name: name.val(),
            email: email.val(),
            message: message.val(),
            human: human.val()
        }, function (html) {
            // if html from script.php == 1, happy days
            if (html == '1') {
                jQuery("#contact").hide()
                success.html("Thank You, your message has been sent.")
                error.show()
            }
            else {
                error.html(html)
            }
        });
    });
});
于 2012-07-10T13:03:15.033 回答