如何通过jQuery在本地日期时间上设置日期时间 [英] How to set datetime on datetime-local via jQuery
本文介绍了如何通过jQuery在本地日期时间上设置日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单上有datetime-local html控件,我需要通过JS或jQuery动态设置日期和时间.我该怎么办?
I have datetime-local html control on my form and I need to set date and time on it dynamically via JS or jQuery. How can I do it?
<input type="datetime-local" id="publishDate" required/>
我尝试过
$("#publishDate").val("2013-3-18 13:00");
$("#publishDate").val("2013-3-18T13:00");
$("#publishDate").val(new Date().toLocalString());
但没有任何效果.
谢谢.
推荐答案
这可以解决问题
$("#publishDate").val("2013-03-18T13:00");
您需要在月份中使用2位数字才能使示例工作.
You need to use 2 digits for the month to make your sample work.
这篇关于如何通过jQuery在本地日期时间上设置日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文