我想在没有 type="submit"按钮的情况下验证表单输入。 我该怎么做?
我试过了 ->
<script type="text/javascript">function validateForm() {
$('#form1')[0].checkValidity()
if( document.form1.vorname.value == "" )
{
return false;
}
if( document.form1.nachname.value == "" )
{
return false;
}
if( document.form1.postleitzahl.value == "" )
{
return false;
}
if( document.form1.email.value == "" )
{
return false;
}
if( document.form1.telefon_optin_Ja.value == "" )
{
return false;
}
if( document.form1.ort.value == "" )
{
return false;
}
if( document.form1.straße.value == "" )
{
return false;
}
if( document.form1.Anrede.value == "" )
{
return false;
}else {
$('#modal_absenden').modal({
backdrop: 'static',
keyboard: 'false',
})
}
}
</script>
我的表单名称是: form1 ,按钮 -> `Absenden
问题的“背景”是:我想首先验证表单输入,然后(如果所有输入正常)它应该打开一个模式,您可以在其中选择重定向页面(重定向是,重定向否),然后它通过邮寄方式将表单提交至 mail.php。
我希望你能理解我的问题,如果你有疑问,请提问。 (我的英语不太好..)
感谢您的帮助。
最佳答案
您提到了 HTML5。
那么这意味着您所要做的就是使用 checkValidity() 和
<input type="text" name="name" required>
<input type="email" name="email" required placeholder="Enter a valid email address">
这是一篇关于使用 HTML5 验证的好文章。
我自己没用过。但我很高兴从你的帖子中了解一些信息。
http://www.the-art-of-web.com/html/html5-form-validation/
如果您想使用 jQuery,请进行验证。 http://www.codeproject.com/Articles/213138/An-Example-to-Use-jQuery-Validation-Plugin
关于javascript - 没有提交按钮的 HTML5 表单验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25805317/