html5原⽣⾃带的⽇期控件和时间控件直接上代码:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>html5原⽣⾃带的⽇期控件和时间控件</title>
<script src="code.jquery/jquery-latest.js"></script>
<script type="text/javascript">
$(function () {
NOW();
});
/
/初始化时间控件
function NOW() {
var now = new Date();
var nowYear = FullYear(); //年
var nowMonth = Month() + 1 < 10 ? "0" + (Month() + 1) : Month(); //⽉
var nowDay = Date() < 10 ? "0" + Date() : Date(); //⽇期
var nowHour = Hours() < 10 ? "0" + Hours() : Hours(); //时
var nowMinute = Minutes() < 10 ? "0" + Minutes() : Minutes(); //分
var nowDate = nowYear + "-" + nowMonth + "-" + nowDay;
var nowTime = nowHour + ":" + nowMinute;
$("#nowDate").val(nowDate);
$("#nowTime").val(nowTime);
}
$(function () {
$("#btnNow").click(function () {
NOW();
});
});
</script>
</head>
<body>
<div>
<input type="date" id="nowDate" />
<input type="time" id="nowTime" />
<input type="button" id="btn" value="获取时间" />html代码转链接
<input type="button" id="btnNow" value="当前时间" />
</div>
</body>
</html>
<script type="text/javascript">
$(function () {
$("#btn").click(function () {
var nDate = $("#nowDate").val();
var nTime = $("#nowTime").val();
alert(nDate + " " + nTime);
});
});
</script>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论