1

我希望 screenCheck 函数显示仅在#contact_email. 但就我而言,它在此之前运行。我该如何纠正?

<script>
function screenCheck() {
    var screenWidth = window.screen.width;
    if (screenWidth == '1024') {
        $('#textAreaMsg label.error').css('margin-left', '99px');
    }
}

$(document).ready(function() {
    $("#contact_email").validate(screenCkeck());​
</script>
4

3 回答 3

3

尝试在没有的情况下通过你的回调()

$("#contact_email").validate(screenCheck);

另请注意,您的函数被调用screenCheck而不是screenCkeck

于 2012-06-22T08:28:36.947 回答
1

在@F旁边。Calderan 提到,我认为你的

$(document).ready(function() {
 $("#contact_email").validate(screenCkeck());​

需要一个)};

$(document).ready(function() {
 $("#contact_email").validate(screenCheck);​
}); // need closing
于 2012-06-22T08:31:47.490 回答
0

Assuming you're using the JQuery validator plugin, you need to pass the callback as part of the options map. For example, to make your callback run after the form has been deemed invalid, you'd write it like this:

$("#contact_email").validate({
    invalidHandler: screenCheck
});

The same goes for the submitHandler and/or the showErrors handler. To handle all three, you'd write it like this:

$("#contact_email").validate({
    invalidHandler: screenCheck,
    submitHandler: submitCallback,
    showErrors: showErrorsCallback
});
于 2012-06-22T08:40:10.347 回答