简体   繁体   English

JavaScript无法停止页面加载

[英]Javascript is unable to stop page loading

I have a sign-up page having proper validation's every place. 我有一个注册页面,每个地方都有正确的验证。 But whenever i click "Sign-Up" on a blank form. 但是每当我单击空白表格上的“注册”。 It shows the validation, but gets loaded. 它显示了验证,但已加载。 I want to stop the loading. 我想停止加载。 How's that possible. 那怎么可能

I am primarily checking on chrome, where i checked on settings, whether javascript is disabled or not, but it is enabled. 我主要是在chrome上检查,在这里我检查设置,是否禁用了javascript,但启用了javascript。

it's happening in an .cshtml page. 它发生在.cshtml页面中。

Feel free to ask any question 随时问任何问题

If you are using validation, you must place the if condition. 如果使用验证,则必须放置if条件。

For example: 例如:

 a = validate('something'); (validate - is the validation function, but you can have another name of function) if (!a) { return false; } else { --your form submit here-- } 

首先可能是您使用<button type="submit"> ..这将强制提交表单,即加载您必须使用<input type="button"> ,然后将验证写为@llkin建议使用return false停止加载页面

<form name="myForm" id="myFormId" onsubmit="myFunction()" novalidate>

</form>

myFunction(){
//you logic goes here
document.getElementById('myFormId').submit();
}

use novalidate attribute to disable to default validation of form and you can use custom function to validate on submit. 使用novalidate属性可以禁用对表单的默认验证,您可以使用自定义函数在提交时进行验证。 In myFunction() define your custom logic to validate and submit the form. 在myFunction()中,定义您的自定义逻辑以验证并提交表单。

DO not use button type submit. 不要使用按钮类型提交。 Onclick call a function where you have to validate all fields and return true/false. Onclick调用一个函数,您必须在其中验证所有字段并返回true / false。 Call that function in your validation function check the value if true submit form. 在验证函数中调用该函数,检查是否为真提交表单。

May be this helps you. 可能对您有帮助。

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

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