如何在文本框中设置默认日期? jQuery的 [英] How to set default date in text box? Jquery

查看:98
本文介绍了如何在文本框中设置默认日期? jQuery的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery 1.10

i am using jquery 1.10

查看模板

<script>
    $(function() {
    $( "#departing_on" ).datepicker({
      dateFormat: "dd-mm-yy",
      numberOfMonths:[1,2],
      minDate: new Date() 
    });
    $( "#return_on" ).datepicker({ 
      dateFormat: "dd-mm-yy",
      numberOfMonths:[1,2],
      minDate: new Date() 
    });
    });
</script>

第一次在文本框中选择我要默认今天的日期.怎么样?

First time while selecting I want default today's date in text box. how ?

推荐答案

$("#departing_on").val($.datepicker.formatDate("dd-mm-yy", new Date()));
$("#return_on").val($.datepicker.formatDate("dd-mm-yy", new Date()));

在脚本末尾添加以上代码.这是必需的,因为datepicker插件在初始化时无权在控件中设置日期.

Add the above code at the end of the script. This is required because the datepicker plugin has no provision to set the date in the control while initializing.

这篇关于如何在文本框中设置默认日期? jQuery的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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