2011-05-08 82 views
1

我有以下代码:的jQuery呼叫功能

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 
     } 
    }); 
} 

我的问题是,如果把这个线$("#form1 :input").attr("disabled", true);的只会验证不执行,但如果我评论的验证功能的伟大工程。问题是为什么我不能执行这两行?我在代码中做了什么错误?

+4

这可能是因为您的验证插件不确实是'disabled'过程表单元素。 – drudge 2011-05-08 02:02:03

+2

你的意思是*验证不执行*?我的猜测是禁用的元素不会被检查,因为它们不会被发送到服务器。 – 2011-05-08 02:02:49

+0

@Felix Kling感谢您的询问,当我谈论验证时,请不要使用验证 – Jorge 2011-05-08 02:07:51

回答

0

我解决我的问题是这样,禁用表单验证把线在验证

/*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 
    } 
}); 
} 
1

我不认为这是你的实际问题,这里的submithanlder后,但值得注意的是,你应该注意getting your curly braces right when you're working with JavaScript。在键名称和值的左括号之间添加换行符可能会导致键名在某些情况下被解释为a JavaScript label

这将是更好的一般都采用这种风格,以避免陷入莫名其妙的错误以后:

// 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 
    } 
    }); 
} 
+0

感谢您的提示我真的很感激 – Jorge 2011-05-08 02:40:38