jquery datepicker:验证当前的输入值? [英] jquery datepicker : Validate current input value?

查看:87
本文介绍了jquery datepicker:验证当前的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用jQuery UI中的Datepicker插件。我想要能够验证其附加的输入文本框当前是否具有有效的日期。



例如:



如果有人决定输入 02/30/2010 我想以某种方式询问插件,如果当前的输入值是有效的日期(不在这种情况下)。



有人知道这可以做什么吗?

解决方案

您可以通过使文本框只读,并根据需要设置日期格式来解决问题。因此,用户无法在文本框中键入任何内容,用户只能从日期选择器中选择正确的日期格式(您设置)。请参阅下面的示例。

 < p>日期:< input type =textid =datepicker =30readonly =readonly/>< / p> 
< script>
$(function(){
$(#datepicker).datepicker();
$(#datepicker).datepicker(option,dateFormat,'yy -mm-dd');
});
< / script>


I've been using the Datepicker plugin from jQuery UI. I want to be able to validate if the input textbox it is attached to currently has a valid date or not.

For example:

If someone decides to type in 02/30/2010 I'd like to be able to somehow ask the plugin if that current input value is a valid date (which it is not in this case).

Does anyone know how this can be done?

解决方案

You can solve your problem by making text box read only and set date format as you like. So User is not able to type anything in text box, user only select correct date format(which you set) from date picker. Please see the below example.

<p>Date: <input type="text" id="datepicker" size="30" readonly="readonly"/></p>    
<script>
$(function() {
    $( "#datepicker" ).datepicker();
    $( "#datepicker" ).datepicker( "option", "dateFormat",'yy-mm-dd');
});
</script>

这篇关于jquery datepicker:验证当前的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆