简体   繁体   English

html表单中的必填字段在chrome中有效,但不能在移动设备上使用(即在wordpress中完成)

[英]required field in html form works in chrome but not mobile or ie (done in wordpress)

I am building a form using html in wordpress. 我正在使用Wordpress中的html构建表单。 The fields that need to be required work in chrome (giving a please fill out this field when the submit button is pressed without information in the field) however it will not work in IE or mobile, it just allows the form to be submitted. 需要填写的字段在chrome中起作用(请按“提交”按钮,但该字段中没有信息,请填写此字段),但是在IE或移动版中将不起作用,它仅允许提交表单。 Here is a sample of a field 这是一个领域的样本

Last name: * 姓: *

input type="text" name="lastname" value="" maxlength="50" required="required"  

I dont know whats going on here and Im pretty new so any help would be appreciated 我不知道这里发生了什么,我还很新,所以我们将不胜感激

(edit with answer) This is what I ended up doing and it works now thanks for the responses (带有答案的编辑)这是我最后要做的,现在可以正常工作了,谢谢您的回答

<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["firstname"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
}
</script>
</head>
<body>
<form name="myForm" form action="dlcplateFormTest.php"  onsubmit="return validateForm()"                   method="POST">
<tr>
<td>Last name: *</td>
<td><input type="text" name="lastname" value="" maxlength="50" required="required"  />            </td>
</tr>
<tr>
<input type="submit" value="Submit" /><input type="reset" value="Reset" />
</form>
</body>
</html>

您需要编写一个JavaScript函数来检查字段是否为“”,如果为“”,则取消请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM