我无法验证此选择

我崩溃了,因为我无法在我的邮件列表表单中执行我的选择的自定义验证。


我有另一个字段,可以在无效时进行验证,但在选择中它似乎不起作用。


让我告诉你我的代码。


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;

  }

}


莫回无
浏览 81回答 1
1回答

梵蒂冈之花

这里:            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;                }            }一个工作示例
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript