[英]OnBlur validation before button click()
i like to know how to validate a text-field at it instant.when ever we move to another text field with out filling the above text-field we need to get an alert message using on-blur(). 我想知道如何在瞬间验证文本字段。每当我们移至另一个文本字段而又不填写上面的文本字段时,我们都需要使用on-blur()获取警报消息。 using java-script.
使用Java脚本。
You can use onblur()
event in javascript 您可以在javascript中使用
onblur()
事件
<input type="text" onblur="test('firstTextBox')"/>
function test(value)
{
if(value == "firstTextBox")
alert("This is blur");
else if ....
.....
}
Have look into jQuery Validate plugin and try the below code to work in onblur
. 查看jQuery Validate插件,并尝试以下代码在
onblur
工作。
$('#field1, #field2, #field3').blur(function(){
validator.validate()
});
If you like to use the html5 form validation take a look at validity
property and set html 5 form attributes like required 如果您想使用html5表单验证,请查看一下
validity
属性并设置html 5表单属性(如必填)
html5: html5:
<input type="number" required="true" onfocus="setCustomValidity('Custom Message')" onblur="testit(this)"/>
js: js:
function testit(e){
if(e.validity.valid == false){
alert(e.validationMessage);
}
}
http://jsfiddle.net/5ANnf/2/ http://jsfiddle.net/5ANnf/2/
https://developer.mozilla.org/en-US/docs/HTML/Forms_in_HTML (at bottom) https://developer.mozilla.org/zh-CN/docs/HTML/Forms_in_HTML (底部)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.