如何更改“请匹配所需格式” 和“无效”
我看起来到处都是Stackoverflow,找不到任何有帮助的东西,它可能是重复的,但是请帮助我!
如果我在字段中键入'asd',然后按 GO ,然后继续键入消息“请匹配所需的格式” 将会出现
我不需要混乱的代码,如果可能的话,我希望它包含在html标签中!
<form id="banner-message">
<input value=""
name="email"
id="inputEmail"
class="form-control"
placeholder="email"
required=""
autofocus=""
oninvalid="this.setCustomValidity('Not Valid')" oninput="setCustomValidity('')"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
<button class="btn btn-lg btn-block" type="submit">Go</button>
</form>
答案 0 :(得分:2)
您需要使用onchange
和this.setCustomValidity
<form id="banner-message">
<input value=""
name="email"
id="inputEmail"
class="form-control"
placeholder="email"
required=""
autofocus=""
oninvalid="this.setCustomValidity('Not Valid')"
onchange="try{setCustomValidity('')}catch(e){}"
oninput="setCustomValidity(' ')"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
<button class="btn btn-lg btn-block" type="submit">Go</button>
</form>
答案 1 :(得分:0)
您也可以只设置title
属性:
<form id="banner-message">
<input value=""
placeholder="email"
required=""
title="Not Valid"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$">
<button class="btn btn-lg btn-block" type="submit">Go</button>
</form>