我有波纹管代码,我想在错误字段下面显示消息而不是气泡。我应该对我的代码添加什么
<script type="text/javascript">
$(document).ready(function() {
$('#emailform').submit(function(event) {
event.preventDefault();
$.ajax({
backedn validation
}
});
});
});
</script>
<body>
<form id="emailform" class="laform" method="post" action="*.php">
<label>Email*: </label>
<input type="email" name="email" id="email" class="input" required oninvalid="this.setCustomValidity('The email address you entered is not valid')" oninput="this.setCustomValidity('')" onchange="try{setCustomValidity('')}catch(e){}">
<label class="col-md-12 labelcom">MSG</label>
<textarea class="input2" name="comment" id="comment" required oninvalid="this.setCustomValidity('This field is mandatory')" oninput="this.setCustomValidity('')" placeholder="Enter your comments / suggestions..."></textarea>
<button type="submit" class="btn" name="submit" value="submit">SUBMIT</button>
</form>
</body>
答案 0 :(得分:0)
无法覆盖HTML required
消息。 More Information
如果验证失败,只需使用Javascript并创建自己的验证检查并在元素下附加消息。
编辑:在做了更多研究后,我发现了另一个包含更多有见地信息的SO post。
显然,这是可能的。但你必须使用Javascript。
此代码更改了HTML required
提供的验证框的消息。您可能应该查看浏览器支持。
document.getElementById("input").setCustomValidity("Message");