gpt4 book ai didi

javascript - 点击提交后页面会刷新

转载 作者:行者123 更新时间:2023-12-03 11:34:44 25 4
gpt4 key购买 nike

我的表单上有多个验证..当我输入错误的数据并单击提交按钮时,它会显示一秒钟的错误消息并且页面会刷新..这只是几个功能。还有其他功能..单独,他们工作得很好。但是当我尝试运行 all 时,它不起作用。

JavaScript:

function req() 
{

if (document.reg_indi_form.txt_fnm.value=="")
{

document.getElementById('i').innerHTML="*This field is required";
document.getElementById('i').style.color="red";
document.getElementById('i').style.fontSize="12px";
}

if (document.reg_indi_form.txt_lnm.value=="")
{

document.getElementById('i1').innerHTML="*This field is required";
document.getElementById('i1').style.color="red";
document.getElementById('i1').style.fontSize="12px";
}
return false;
}

function validateUname() {
submitFlag = true;
var len=document.reg_indi_form.txt_usrnm.value.length;
if(len<6){
submitFlag=false;
document.getElementById('i2').innerHTML="*enter atleast 6 char";
document.getElementById('i2').style.color="red";
}
return submitFlag;
}



function alls()
{
req();
validateUname();


}

html:

<form name="reg_indi_form" method="post" onSubmit="return alls()"         enctype="multipart/form-data">

我的文件中还有 php 代码。

最佳答案

将函数 alls() 更改为:

function alls()
{
return req() && validateUname(); // Your function must return false otherwise it will be considered as true
}

每当您绑定(bind)事件并想要停止传播时,只需返回 false (您正在执行的操作),但您的函数 alls() 不会返回任何不会进一步停止事件传播的内容。

关于javascript - 点击提交后页面会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26571563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com