<script>
function check() {
var pass1=document.getElementById("pass1")
var pass2=document.getElementById("pass2")
var email=document.getElementById("email")
if(pass1.value!=pass2.value){
pass2.setCustomValidity("密码不一致。")
}
else if(pass1.value==pass2.value){
pass2.setCustomValidity("")
}
else if(!email.checkValidity()){
email.setCustomValidity("请输入正确的Email地址。")
}
else{
email.setCustomValidity("")
}
}
</script>
html5表单验证用placeholder显示错误提示:
1、html5包含校验的placeholder如下:
<form action="#" method="post">
<div>
<label for="name">Text Input:</label>
<input type="text" placeholder="Your name" name="name" id="name" value="" tabindex="1" />
</div>
<div>
<label for="name_2">Text Input 2:</label>
<input type="text" placeholder="Your name" name="name_2" id="name_2" value="" tabindex="1" />
</div>
<div>
<label for="textarea">Textarea:</label>
<textarea placeholder="Some text" cols="40" rows="8" name="textarea" id="textarea"></textarea>
</div>
<div>
<label for="textarea">Textarea 2:</label>
<textarea placeholder="Some text" cols="40" rows="8" name="textarea_2" id="textarea_2"></textarea>
</div>
<div>
<input type="submit" value="Submit" />
</div>
</form>
2、css样式:
::-webkit-input-placeholder {
color: #999
}
:-moz-placeholder {
color: #999
}
::-moz-placeholder {
color: #999
}
:-ms-input-placeholder {
color: #999
}
/* Different color for some fields */
#name_2::-webkit-input-placeholder,
#textarea_2::-webkit-input-placeholder
{
color: #FF0000
}
#name_2:-moz-placeholder,
#textarea_2:-moz-placeholder
{
color: #FF0000
}
#name_2::-moz-placeholder,
#textarea_2::-moz-placeholder
{
color: #FF0000
}
#name_2:-ms-input-placeholder,
#textarea_2:-ms-input-placeholder
{
color: #FF0000
}
3、运行效果:
提交出错就是红色的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)