本文介绍了我可以使用HTML输入类型“日期”吗?只收集一年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要从用户处收集一年的字段(即具有一年分辨率的日期 - 为了便于存储,我倾向于存储实际日期值而不是数字)。



我想使用现代浏览器支持的日期输入用户界面或,因为它很好,并且可以很好地与现代平台搭配。我无法弄清楚如何让用户界面只显示一年。任何想法?



如果没有平台支持,理想情况下我想有一个像你一样的UI 如果点击预览,然后点击小部件的顶部几次,除了反过来说:当你第一次点击输入时,你会得到一个包含数十年的列表的小部件,然后你深入下去选择年份,然后关闭UI。

解决方法

不,你不能,只支持一年,所以你需要一个脚本,比如jQuery或者webshim链接,




如果jQuery是一个选项,下面是一个选项,从:

  $(function(){
$(#datepicker ).datepicker({dateFormat:'yy'});
});
CSS

.ui-datepicker-calendar {
d isplay:无;
}

Src:



Src小提琴:



这里是,不含月份和上一个/下一个按钮






如果 bootstrap 是一个选项,,他们有你想要的布局。


I have a field that is required to collect a year from the user (i.e. a date with a year resolution - for ease of storage I'd prefer to store an actual date value and not a number).

I would like to use the date input UI supported by modern browsers or webshims because its nice and plays well with modern platforms. I couldn't figure out how to get the UI to display only the year. Any ideas?

If there is no platform support, ideally I would like to have a UI something like you can see here if you click "Preview" and then click the top of the widget a couple of times, except in reverse: when you first click the input you get a widget with a list of decades, then you drill down to choose the year, then the UI closes.

解决方案

No, you can't, it doesn't support only year, so to do that you need a script, like jQuery or the webshim link you have, which shows year only.


If jQuery would be an option, here is one, borrowed from Sibu:

$(function() {
    $( "#datepicker" ).datepicker({dateFormat: 'yy'});
    });​
CSS

.ui-datepicker-calendar {
   display: none;
}

Src: https://stackoverflow.com/a/13528855/2827823

Src fiddle: http://jsfiddle.net/vW8zc/

Here is an updated fiddle, without the month and prev/next buttons


If bootstrap is an option, check this link, they have a layout how you want.

这篇关于我可以使用HTML输入类型“日期”吗?只收集一年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 01:03