在输入类型日期设置日期 [英] set date in input type date
本文介绍了在输入类型日期设置日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<input id="datePicker" type="date" />
我将在chrome中的datepicker输入类型日期中设置日期。
i will set today date in datepicker input type date in chrome.
$(document).ready( function() {
var now = new Date();
var today = now.getDate() + '/' + (now.getMonth() + 1) + '/' + now.getFullYear();
alert(today);
$('#datePicker').val(today);
});
但它不工作
编辑这个jsFiddle - 请尝试chrome。
Edit This jsFiddle - Please try in chrome.
推荐答案
小提琴链接: http://jsfiddle.net/7LXPq/93/
这两个问题:
- HTML 5中的日期控制以格式年份 - 月 - 日,因为我们在SQL中使用
- 如果月份为9,则需要将其设置为09不是9。所以它也适用于日字段。
请按照小提琴链接进行演示:
Please follow the fiddle link for demo:
var now = new Date();
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
$('#datePicker').val(today);
这篇关于在输入类型日期设置日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文