开发者

jQuery call to functions

I have the following code:

var x;
x=$(document);
x.ready(initEvents);

function initEvents()
{
    var x;
    x = $("#send");
    x.click(pressButton);
    x = $("#clean");
    x.click(cleanForm);
}

/*this method  validates the form*/
function pressButton()
{   
    $("#form1 :input").attr("disabled", true);

    $("#form1").validate(
    {   rules:
        {
            //sets the rules for validate
        },
        messages:
        {
            //sets the message for validates
        },
        submitHandler: function (form)
        {
            //send the form
        }
    });
}

My problem is that if a put this line $("#form1 :input").attr("disabled", true); the validates don't executes but if I commented the validate function works great. The question is why can't I e开发者_StackOverflow社区xecute the two lines? What am I doing wrong in the code?


I don't think this is your actual problem here, but it's worth noting that you should pay attention to getting your curly braces right when you're working with JavaScript. Adding the line break between the key name and the opening brace of the value may cause the key name to be interpreted as a JavaScript label in some cases.

It would be better to generally use this style, to avoid running into strange errors later on:

// Why complicate this?
$(document).ready(initEvents);    

function initEvents() {
  $("#send").click(pressButton);
  $("#clean").click(cleanForm);
}

/*this method  validates the form*/
function pressButton() {   
  $("#form1 :input").attr("disabled", true);

  $("#form1").validate({
    rules: {
      // the rules for validate
    },
    messages: {
      //sets the message for validates
    },
    submitHandler: function (form) {
      //send the form
    }
  });
}


I solved my problem like this, disabled the form after the validation putting the line in the submithanlder of the validation

/*this method  validates the form*/
function pressButton()
{   


$("#form1").validate(
{   rules:
    {
        //sets the rules for validate
    },
    messages:
    {
        //sets the message for validates
    },
    submitHandler: function (form)
    {
        //disable the form
        $("#form1 :input").attr("disabled", true);
        //send the form
    }
});
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜