gpt4 book ai didi

javascript - jquery datepicker - 计算日期差异

转载 作者:数据小太阳 更新时间:2023-10-29 05:50:41 24 4
gpt4 key购买 nike

我是新手,我真的需要你的帮助,因为我已经为此苦苦挣扎了好几天......我想计算用日期选择器选择的两个日期之间的天数。我是在正确的轨道上还是我做的完全错了?我所知道的是,当我点击天数时,它没有显示任何内容。这是我的代码

    <!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function () {

$("#datepicker").datepicker({ minDate: "01/07/2012", maxDate: "01/30/2012" });

$("#datepicker1").datepicker({ beforeShow: setminDate });

var start1 = $('#datepicker');
function setminDate() {
var p = start1.datepicker('getDate');
if (p) {
var k ="01/30/2012";
return {
minDate: p,
maxDate:k
}};
}
function clearEndDate(dateText, inst) {
end1.val('');
}
});
$(function() {
$( "#datepicker1" ).datepicker({ dateFormat: 'mm/dd/yyyy' });
$( "#datepicker" ).datepicker({ dateFormat: 'mm/dd/yyyy' });
});
$('button').click(function() {
var start = $('#datepicker1').datepicker('getDate');
var end = $('#datepicker').datepicker('getDate');
var days = (end - start)/1000/60/60/24;
alert(days);
});
</script>
<body>
<form>
from:
<input id="datepicker" readonly='true'/><br>
to:
<input id="datepicker1" readonly='true'/><br>
</form>
<br><button>number of days</button>

</body>
</html>

最佳答案

进行此更改后为我工作

    var start = $('#datepicker').datepicker('getDate');
var end = $('#datepicker1').datepicker('getDate');
var days = (end - start)/1000/60/60/24;
alert(days);

jsfiddle:http://jsfiddle.net/diode/L2et3/3/

关于javascript - jquery datepicker - 计算日期差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8901649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com