如何在 html 页面中使用 Javascript 获取简单的日历窗口

我是 JS 新手,我想知道,如何使用 JS 获得一个简单的日历窗口。实际上,我想编写一个简单的函数来获取选定的日期,以便稍后在我的代码中将该日期用作字符串。


万千封印
浏览 144回答 2
2回答

九州编程

在 jQuery 中<input type="date" id="calendar" /><button id="btn">get</button><script type="text/javascript">&nbsp; &nbsp; $("#btn").on("click", function () {&nbsp; &nbsp; &nbsp; &nbsp; var date = new Date($("#calendar").val());&nbsp; &nbsp; &nbsp; &nbsp; var day = date.getDate();&nbsp; &nbsp; &nbsp; &nbsp; var month = date.getMonth() + 1;&nbsp; &nbsp; &nbsp; &nbsp; var year = date.getFullYear();&nbsp; &nbsp; &nbsp; &nbsp; alert(day);&nbsp; &nbsp; &nbsp; &nbsp; alert(month);&nbsp; &nbsp; &nbsp; &nbsp; alert(year);&nbsp; &nbsp; });</script>

繁花如伊

你可以创建一个服务器端日历,我刚刚完成了一个。唯一的问题是与日历的任何交互都需要回发,而不是最佳的。你的后端用的是什么?如果是 ASP.NET MVC,我将分享我的日历部分视图,您可以更新它以使用表格,不寒而栗,而不是 Bootstrap 来定位日期。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript