<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../../js/jquery-3.1.1.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
</head>
<body>
<p>您开始写博客的时间:<input type="text" id="datepicker"></p>
<p>你放弃写博客的时间:<input type="text" id="datepicker1"></p>
<button onclick="jisuan()">算一下</button>
<span id="result"></span>
</body>
<script type="text/javascript">
var sDate = "";
var eDate = "";
$(function() {
$( "#datepicker" ).datepicker();
$( "#datepicker1" ).datepicker();
});
function jisuan() {
sDate = $("#datepicker").val();
eDate = $("#datepicker1").val();
var sArr = sDate.split("/");
var eArr = eDate.split("/");
var sRDate = new Date(sArr[2], sArr[0], sArr[1]);
var eRDate = new Date(eArr[2], eArr[0], eArr[1]);
var result = (eRDate-sRDate)/(24*60*60*1000);
$("#result").text("您写博客"+result+"天了");
}
</script>
</html>
jQuery原生时间选择器加减--实例
最新推荐文章于 2022-05-11 15:23:44 发布