“成功”功能如何运作,我该如何模仿呢?

时间:2013-03-01 21:16:33

标签: javascript jquery ajax validation

我正在开发一个验证框架,需要一个布尔结果才能知道验证是否成功。

以下是我正在做的事情的快速浏览:

Stone.Validation({
 id:  "#InputTextId",//the id of the input you want to validate
 DataType: "string",//the Data Type of want to valide(string and integer for now are avaiable)
 MsgOk: "Correct",//optional: the msg you want to display if it is a string
 MsgWrog: "* Check this field",////optional: the msg you want to display if its not a string
 Destiny: "#someDivID",//the id that will some the correct of error message
})

如果验证失败,我不知道如何禁用表单提交。它只返回消息,但不返回布尔值或类似的东西。

我正在寻找的例子:

Stone.Validation({
 id:  "#InputTextId",
 DataType: "string",
 MsgOk: "Correct",
 MsgWrog: "* Check this field",
 Destiny: "#someDivID",
 success: function(results)
{
   if(results)
    {
      //submit will work
    }
}
})

1 个答案:

答案 0 :(得分:0)

要控制表单提交,您必须使用表单的提交事件。以下是使用jQuery的方法:

$('form').submit(function(){
    // validate your form first
    if(!formIsValid) {
        // if validation didn't pass, cancel submission
        return false;
    }
});
相关问题