控制台日志一直说该功能未定义 onClick 此按钮。我真的不知道为什么。我有 2 个使用相同格式的其他弹出窗口,当我为每个弹出窗口按下每个按钮时,它们都说函数未定义。该页面没有说明有任何明显的 javascript 语法错误。
谢谢你的帮助
HTML
<div class="popup" id="popup-subscribe">
<div id="close-subscribe" class="close-button"> </div>
<div class="popup-title">Subscribe</div>
<form method="post" name="subscribe" action="">
<span class="label" style="margin-right: 5px">Name: </span><input type="text" placeholder="Name" name="name" /><br>
<span class="label" style="margin-right: 5px">Email: </span><input type="text" placeholder="Email" name="email_subscribe" /><br>
<div class="errors" id="subscribe-errors"></div>
<div onclick="validateSubscribeForm()" class="button-medium">Sign me up!</div>
</form>
</div>
Javascript
function validateSubscribeForm() {
var emailSubscribe =document.forms["subscribe"]["email_subscribe"].value;
var atpos=emailSubscribe.indexOf("@");
var dotpos=emailSubscribe.lastIndexOf(".");
var name = document.forms["subscribe"]["name"].value;
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=emailSubscribe.length)
{
$("#subscribe-errors").html("The email you entered is not valid");
return false;
}
else if (name == null || name == "")
{
$("#subscribe-errors").html("Please enter a name");
}else {
document.subscribe.submit();
}
}
具体来说,控制台日志错误状态: Uncaught ReferenceError: validateSubscribeForm is not defined