我崩溃了,因为我无法在我的邮件列表表单中执行我的选择的自定义验证。我有另一个字段,可以在无效时进行验证,但在选择中它似乎不起作用。让我告诉你我的代码。function validate() { var x = document.forms["mlist-form"]["EMAIL"].value; if (x == "") { document.getElementById("email-error").innerHTML = "Email Address is required."; document.getElementById("email-error").style.display = "block"; return false; } document.getElementById("email-error").innerHTML = "Please enter a valid Email Address."; document.getElementById("email-error").style.display = "block";}document.addEventListener('invalid', (function() { return function(e) { //prevent the browser from showing default error bubble / hint e.preventDefault(); // optionally fire off some custom validation handler // myValidation(); };})(), true);function countryError() { var f = document.forms["mlist-form"]["COUNTRY"].value; if (f = "") { document.getElementById("country-error-label").innerHTML = "Country is required."; document.getElementById("country-error-label").style.display = "block !important"; return false; }}
1 回答
梵蒂冈之花
TA贡献1900条经验 获得超5个赞
这里:
function countryError() {
var f = document.forms["mlist-form"]["COUNTRY"];
var country = f.options[f.selectedIndex].value;
if (country == "") {
document.getElementById("country-error-label").innerHTML = "Country is required.";
document.getElementById("country-error-label").style.display = "block !important";
return false;
}
}
添加回答
举报
0/150
提交
取消