通过jquery设置HTML5输入类型的值= week [英] Setting the value of HTML5 input type=week thru jquery

查看:346
本文介绍了通过jquery设置HTML5输入类型的值= week的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Javascript / Jquery中设置HTML5的输入类型=周的默认值?我正在使用moment.js来简化操作。

How to set the default value of HTML5's input type="week" in Javascript/Jquery? I'm using moment.js to make things easier.

HTML

<input type="week" id="weekpicker" />

Javascript

$('#weekpicker').val(moment().format('YYYY-MM-DD'));

上面的代码不起作用。

推荐答案

我是这样做的(使用momentjs): http://momentjs.com/docs/#/get-set/

Here's how I did it (using momentjs): http://momentjs.com/docs/#/get-set/

$('#weekpicker').val(moment().weekYear() + "-W" + moment().week());

首先我得到 weekYear (不是年份,因为第一周的第一天并不总是落在一年的第一天,有时候周年与月份不同。来源: http://momentjs.com/docs/#/get-set/week-year/ )然后我连了一封信<强烈>W格式需要,然后我得到。我把它们加在一起得到了: 2014-W47

First I get the weekYear (not the year, Because the first day of the first week does not always fall on the first day of the year, sometimes the week-year will differ from the month year. source: http://momentjs.com/docs/#/get-set/week-year/) then I concatenated a letter "W" as the format requires, then I get the week. I added it all together and got: 2014-W47

这篇关于通过jquery设置HTML5输入类型的值= week的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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