gpt4 book ai didi

使用 Onclientclick 或 Onsubmit 都不会调用 JavaScript 函数

转载 作者:太空宇宙 更新时间:2023-11-04 15:32:58 24 4
gpt4 key购买 nike

我正在尝试对我的登录页面应用验证。为此使用了一个单独的 JavaScript 函数,但不会以任何方式调用该函数。

<script type="text/javascript">
function myFunction() {
var pass = document.getElementById("passwordsignup").value;
var ConfirmPass = document.getElementById("passwordsignup_confirm").value;
var email = document.getElementById("emailsignup").value;
var uname = document.getElementById("usernamesignup").value;

var PassExpr = "/^[a-zA-Z0-9!@#$%^&*]{6,16}$/";
var emailExp = "/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([com\co\.\in])+$/";

if (uname == "" && email == "" && pass == "" && ConfirmPass == "") {
alert("All Feilds are Required");

return false;
}
if (uname == "")
{
alert("Please Enter User Name !!");
return false;

}
if (email == "")
{
alert("Please Enter Email !!")
return false;
}
else {
if (!email.match(emailExp)) {
alert("Please Enter Valid Email Id");
return false;
}
}
if (pass == "")
{
alert("Please Enter Password..!!");
return false;
}
else {
if(pass.length>6 && pass.length<16)
{
if (!PassExpr.test(pass)) {
alert("password should contain atleast one number and one special character");
return false;
}
}

else {
return false;
}

}
if (ConfirmPass == "")
{
alert("Please Re-Enter Password..!!");
return false;
}
else {
if (pass != ConfirmPass) {
alert("Please Re-Enter Password to Match !!!!!");
return false;
}
}
}

我的表格是:

 <div id="register" class="animate form">
<form id="form2" runat="server" onsubmit="return myFunction();">
<h2> Sign up </h2>
<p>
<label for="usernamesignup" class="uname">UserName</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="User Name" runat ="server" onchange="checkUserName();"/>
<%--<asp:TextBox ID="usernamesignup1" runat="server" OnTextChanged="checkUserName()" ></asp:TextBox>--%>
<asp:Label ID="LabelStatus" runat="server" Text="Label"></asp:Label><br />
</p>
<p>
<label for="emailsignup" class="youmail" >Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="Email" runat="server" />

</p>
<p>
<label for="passwordsignup" class="youpasswd">password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="Password" runat="server"/>
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd">Please confirm your password&nbsp; </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" title="Please enter the same Password as above." type="password" placeholder="Re-Enter Password" runat="server"/>
</p>

<p class="login button">
<%--<asp:Button ID="btnSignup" runat="server" Text="Sign Up" OnClick="Button1_Click" Width="150px" CssClass="btnSignup" Height="46px" />&nbsp&nbsp&nbsp&nbsp&nbsp</p>--%>
<asp:Button ID="btnSignup" runat="server" Text="Sign Up" onClientClick="return myFunction();" OnClick="btnSignup_Click" Width="150px" Height="40px"/>
</p>

表单提交时未检查验证。还有其他方法可以调用 JavaScript 函数吗?

最佳答案

您遇到任何 JavaScript 错误吗?打开浏览器控制台,您将看到未捕获的语法错误。

关于使用 Onclientclick 或 Onsubmit 都不会调用 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44648580/

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