简体   繁体   English

更改jQuery表单验证的值

[英]change the value of the jquery form validation

I am using jquery form validation to alert the user if the form is not valid. 我正在使用jQuery表单验证来警告用户表单是否无效。

if (!$(Form1).valid()) {
    alert("invalid form")
}

is there a way to force the form to be invalid in javascript. 有没有一种方法可以强制表单在javascript中无效。

for example I have a textbox and if it's value is "123" I want the form to become invalid. 例如,我有一个文本框,如果它的值为“ 123”,则我希望该表单无效。

something like this: 像这样的东西:

if($("#TextBox1").val()=="123"){
    $(Form1).valid() = false;
}

you can set the value (true or false) to a variable 您可以将值(真或假)设置为变量

if($("#TextBox1").val()=="123"){
    var responce1 = false;
}
if($("#TextBox2").val()=="abc"){
    var responce2 = false;
}

and at last you can check as 最后您可以检查为

 var resultresponce=responce2 && responce1;

and lastly you need to check if the value of resultresponce is true... if so you can submit the form or else not.. 最后,您需要检查resultresponce的值resultresponce为true ...如果是,则可以提交表单。

if(resultresponce)
{
$(form).submit();
}

You should try to just use a if statement for this one. 您应该尝试仅对此使用if语句。 Something like: 就像是:

if ($("#el").val() == "123") {
    // Do something or nothing here.

} else if (!$(Form1).valid()) {
    alert("invalid form")

} else {
    // All correct

}

What philnate says should also work fine. 集邮所说的也应该可以。 It's more what you want to happen. 这是想要发生的更多事情。

What you can do to invalidate the Form is to disable the connected submit button, so the user can't submit it. 要使表单无效,您可以做的是禁用连接的提交按钮,以便用户无法提交它。 See: jQuery disable/enable submit button 请参阅: jQuery禁用/启用提交按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM