Javascript “成功”功能是如何工作的?我如何模仿它?

Javascript “成功”功能是如何工作的?我如何模仿它?,javascript,jquery,ajax,validation,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",//optio

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

下面是我正在做的事情的简要介绍:

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

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

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

为什么在没有jQuery的情况下使用HTML ID?如果我使用它会有问题吗?是的。当您引用HTML id时,您需要添加$(“#id name”)以使jQuery.OMG能够识别它,我不知道让我们先澄清一下这个id:
#myid
实际上来自CSS。它在jQuery(
$('#myid')
中工作,并与本机
文档一起工作。queryselectoral('#myid')
。但这将失败:
document.getElementById(“#myid”)
。它应该是
document.getElementById('myid')
。所有考虑标记的内容都类似于