defaultDate选项与setDate方法之间的区别 [英] Differences between defaultDate option vs setDate method

查看:613
本文介绍了defaultDate选项与setDate方法之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQueryUI DatePicker来解决问题.我必须了解的主要内容之一是在页面加载时设置日期的方式.

I am trying to get my head around using jQueryUI DatePicker. One of the main things I must understand is the way a date can be set on page load.

做过一些研究后,我发现了两种不同的方法:

After doing some research, I found 2 different ways to do this:

  1. 使用defaultDate选项
  2. 使用setDate方法
  1. using defaultDate option
  2. using setDate method

到目前为止,我发现的主要区别是defaultDate选项仅设置datePicker日历本身中的值.

The main difference I found out so far is that the defaultDate option only sets the value in the datePicker calendar itself.

setDate方法设置input type text和&在datePicker日历本身中.

Whereas the setDate method sets both the date in the input type text & in the datePicker calendar itself.

一件有趣的事情是,当使用setDate方法&同时使用defaultDate选项,使用setDate方法设置的日期将覆盖使用defaultDate选项设置的日期的值.

One interesting thing is that when using setDate method & defaultDate option simultaneously, the date set using setDate method overrides the value of the date set using the defaultDate option.

请参见 http://jsfiddle.net/vb7mu3sf/

我注意到了另外两个区别:

Another couple of differences I noticed:

  • 都接受日期作为日期类型作为参数(非常简洁),但是defaultDate选项接受其他类型(数字和字符串).
  • 当然,可以在datePicker上随时调用
  • setDate方法
  • both accepts the date as a Date type as a parameter (which is very neat) but defaultDate option accepts additional types (Number & String).
  • setDate method can of course be called at anytime on the datePicker

还有其他我想念的区别吗?

Is there anything else I missed about their differences?

资源:

  • http://api.jqueryui.com/datepicker/#option-defaultDate
  • http://api.jqueryui.com/datepicker/#method-setDate
  • jQuery-UI datepicker default date

推荐答案

看一下文档:

defaultDate
如果该字段为空白,则将日期设置为在第一次打开时突出显示.

defaultDate
Set the date to highlight on first opening if the field is blank.

setDate
设置日期选择器的日期.

setDate
Sets the date for the datepicker.

没有太多要解释的了.如上所述:

There is not much left to explain. As mentioned above:

  • 设置defaultDate属性:
    • 设置日历打开且字段为空白时的重点日期.
    • 不更新该字段.
    • 用户必须按Enter或单击日期才能更新该字段.
    • Setting the defaultDate property:
      • Sets the date that is focused when the calendar opens and the field is blank.
      • Does not update the field.
      • User has to hit enter or click a date in order to update the field.
      • 更新字段.
      • 在不为空的字段中打开日历会导致该日期成为重点 selected .

      可能使用一种技术或另一种技术:

      Possible uses of one technique or the other:

      • 如果日期是必填字段-并且-有默认值,则使用setDate方法.如果用户对输入的日期没问题,则可以节省两次单击.
      • 否则,如果用户选择激活日期选择器,请使用defaultDate指定要聚焦的日期.
      • If the date is a mandatory field -and- there is a default value then use the setDate method. This saves two clicks if the user is OK with the pre-entered date.
      • Otherwise, use the defaultDate to specify the date that is focused should the user choose to activate the datepicker.

      注意:

      ...但是defaultDate选项接受其他类型(数字和字符串).

      ... but defaultDate option accepts additional types (Number & String).

      实际上,setDate接受defaultDate所做的所有日期版本.

      Actually, setDate accepts all versions of date that defaultDate does.

      当然,可以随时在datePicker上调用

      setDate方法

      setDate method can of course be called at anytime on the datePicker

      那么,defaultDate选项也可以随时设置.例如,如果有两个日历,例如签入和签出,用户选择了一个签入日期为2014年11月10日,那么您希望将另一个日历上的defaultDate设置为2014年11月11日.

      Well, the defaultDate option can be set anytime as well. For example, if there are two calendars e.g. checkin and checkout and the user chose a checkin date Nov 10, 2014 then you would want to set the defaultDate on the other calendar to be Nov 11, 2014.

      这篇关于defaultDate选项与setDate方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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