“成功”功能是如何运作的,我该如何模仿它

How does the `success` function work and how can I imitate it?

本文关键字:何模仿 何运作 成功 功能      更新时间:2023-09-26

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

这里是我正在做的快速查看:

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

要控制表单提交,必须使用表单的submit事件。下面是如何使用jQuery实现这一点:

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