gpt4 book ai didi

JavaScript 警报/确认错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:05 25 4
gpt4 key购买 nike

目前,当新用户在我的网站注册时,他们必须填写一些表格。如果他们的密码太短、不匹配、他们没有填写所有字段或任何其他错误,我想提醒他们。目前它没有提醒他们,所以我切换到确认。这也不起作用,所以我考虑使用 showModalDiaglog。那也没有用,我没有想法。我目前有这个:

HTML

<form>
First Name:<br/> <input id="firstname"/><br/>
Last Name: <br/> <input id="lastname"/><br/>
Age: <br/> <input id="age"/><br/>
Your Email:<br/> <input id="email"/><br/>
Username: <br/> <input id="username"/><br/>
Password: <br/> <input id="password"/><br/>
Confirm Password:<br/> <input type="password" id="passwordconfirm"/><br/>
<br/>
<button size=20 onClick='getRegistrationFields()'>Submit</button>
</form>​

JavaScript

function getRegistrationFields() {
var first = document.getElementById("firstname").value;
var last = document.getElementById("lastname").value;
var email = document.getElementById("email").value;
var age = document.getElementById("age").value;
var username = document.getElementById("username").value;
var password = document.getElemetnById("password").value;
var confirm = document.getElementById("passwordconfirm").value;
var empty = "";

if ((first === empty) || (last === empty) || (email === empty) || (age === empty)
|| (username === empty) || (password === empty) || (confirm === empty)) {
var message = "Not all of the fields are filled out";
prompt(message);
//showModalWindow("fields");
return false;
}

else {
age = parseInt(age);

if (password.length < 10) {
var message2 = "Password must be at least 10 characters long";
prompt(message2);
//showModalWindow("passwordlength");
return false;
}

else if (password != confirm) {
var message3 = "Passwords Do not match";
prompt(message3);
//showModalWindow("passwordmatch");
return false;
}

else if (age < 18) {
var message4 = "You must be older to register for this software.";
prompt(message4);
//showModalWindow("young");
return false;
}

else {
var message5 = "All of the fields are correct. We will be processing your request";
prompt(message5);
//showModalWindow("success");
return true;
}
}
}

function showModalWindow(fileName) {
window.showModalDialog("alerts/" + url + ".html", "", "resizable: no; height: 150; width: 350;");
}

最佳答案

尝试

html:

<button size="20" id="btn_submit">Submit</button>

js:

var btn_submit = document.getElementById("btn_submit");
btn_submit.onclick = getRegistrationFields;

关于JavaScript 警报/确认错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10865931/

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