当鼠标模糊时如何验证输入的日期

时间:2022-12-16 18:58:46

How to validate the inputed date when mouse blur? If the entered date is incorrect then show the current date in textbox

当鼠标模糊时如何验证输入的日期?如果输入的日期不正确,那么在文本框中显示当前日期

<p>Date:
<input id="datepicker" type="text">
</p>
<script>
$("#datepicker").datepicker();
</script>

my fiddle http://jsfiddle.net/kannankds/uWwtc/

我的小提琴http://jsfiddle.net/kannankds/uWwtc/

3 个解决方案

#1


2  

use blur function to do that

使用模糊函数来实现这一点。

$("#datepicker").on('change',function(){ your code});

$(" # datepicker ")。(“改变”,函数(){代码});

Fiddle Example

小提琴的例子

#2


1  

You can use like this:

你可以这样使用:

$("#datepicker").on('blur',datepicker);

But I would recommend you to use change instead of blur:

但是我建议你使用改变而不是模糊:

$("#datepicker").on('change',datepicker);

#3


1  

you can also do this:

你也可以这样做:

<p>Date:
<input id="datepicker" type="text" onblur="check()">
</p>

<script>   
 function check()
 {
     //put validations here
  }
</script>

#1


2  

use blur function to do that

使用模糊函数来实现这一点。

$("#datepicker").on('change',function(){ your code});

$(" # datepicker ")。(“改变”,函数(){代码});

Fiddle Example

小提琴的例子

#2


1  

You can use like this:

你可以这样使用:

$("#datepicker").on('blur',datepicker);

But I would recommend you to use change instead of blur:

但是我建议你使用改变而不是模糊:

$("#datepicker").on('change',datepicker);

#3


1  

you can also do this:

你也可以这样做:

<p>Date:
<input id="datepicker" type="text" onblur="check()">
</p>

<script>   
 function check()
 {
     //put validations here
  }
</script>