即使是这个简单的警报,我都在努力工作。我必须创建一个非常简单的动态网站,用户尝试通过表单元素登录牙科诊所的网站,该表单元素输入其姓名,电子邮件,ID和密码。然后,他们检查是否要通过电子邮件进行确认,最后选择要完成的交易。
分配实际上并不需要我们使用任何数据库,我们只需要创建两个Javascript函数即可。一种用于验证所有字段均已正确填充(称为“验证”),另一种用于查看该用户是否在系统中(称为“验证”)。按下继续按钮后,将显示一条简单消息,显示您的姓名,表示您正在执行已完成的交易。
由于某种原因,单击时甚至不会调用我创建的简单警报功能,这令人难以置信。我使用JavaScript的方式有误吗?另外,我的其余代码是否可以按预期目的正常工作。用户输入的数据是否可以访问?
function User(name, email, password, ID) {
this.name = name;
this.email = email;
this.password = password;
this.ID = ID;
}
var User1 = new User(Kathy Pasos, kps @gmail.com, Pikachu2, 12345678);
var User2 = new User(Martha Pasqual, MarthaP @gmail.com, Pidgey79, 12652526);
var User3 = new User(Patrick Pavlick, pavlickP @njit.edu, Squirtl3, 13577710);
var User4 = new User(Joao Pedro, jps28 @njit.edu, Zubat21, 14308207);
var User5 = new User(Joe Perry, JAP @gmail.com, JE0000, 12696894);
var User6 = new User(Mario Costa, MCS @gmail.com, MC145, 07206143);
var Users = new Array(User1, User2, User3, User4, User5, User6);
function clickAlert() {
alert('Hello');
}
function validation() {
alert('Test');
if (document.getElementById("email").includes("@") && document.getElementById("email").includes(".")) {
Email = document.getElementById("email").value;
return;
} else {
alert("That's not a valid email!");
return;
}
}
<form>
<div class="form-group">
<label for="text">Name:</label>
<input type="text" class="form-control" id="text">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="form-group">
<label for="number">ID:</label>
<input type="number" class="form-control" id="number">
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="Confirmation">Receive
email confirmation of any transaction
</label>
</div><br>
<label for="list">Select an Option:</list><br>
<select name="Select an Option:" id="list">
<option value="sched">Schedule an Appointment</option>
<option value="cancel">Cancel an Appointment</option>
<option value="search">Search for Appointment(s)</option>
<option value="create">Create/Register an Account</option>
</select><br>
<br><div>
<input type="button" class="btn btn-primary mb-2" onclick="clickAlert()"
value="Continue">
</div>
</form>
答案 0 :(得分:-1)
尝试一下:
<input type="submit" class="btn btn-primary mb-2" onclick={clickAlert()} value="Continue">