gpt4 book ai didi

javascript - 为什么这个 Javascript 函数不显示 alert()?

转载 作者:行者123 更新时间:2023-12-05 09:27:56 26 4
gpt4 key购买 nike

<分区>

如果两个元素未填写,我有一个显示警报的功能,但警报没有显示,它只是重新加载页面。不确定我错过了什么或哪里出错了。这是 Javascript:

function submitNewsletter() {
var name = document.getElementById("name");
var email = document.getElementById("email");
if (name == "" || email == "") {
alert("Please fill in your details.");
return false;
}
}

这是它的 html:

<section class="signup">
<h1>Keep up to date.</h1>
<p>Sign up to our newsletter to hear about improvements and additions to Electric Dreams.</p>
<form class="newsletterForm">
<label for="name" class="label">Full Name</label>
<input type="text" id="name" name="name" class="input" placeholder="Full Name"> <br>
<label for="email" class="label">Email Address</label>
<input type="email" id="email" name="email" class="inout" placeholder="Email Address"> <br>
<button type="submit" class="btn" onclick="submitNewsletter()">Submit</button>
</form>
</section>

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