jquery datepicker:验证当前的输入值? [英] jquery datepicker : Validate current input value?
问题描述
例如:
如果有人决定输入 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屋!