Possible Duplicate:
Difference in Months between two dates in JavaScript
<input type="text" id="month1" value="11"><input type="text" id="year1" value="1988"> <br />
<input type="text" id="month2" value="03"><input type="text" id="year2" value="2010"> <br />
<input type="submit" id="show">
$("#show").click(function(){
var m1 = $("#month1").val();
var m2 = $("#month2").val();
var y1 = $("#year1").val();
var y2 = $("#year2").val();
var result = 'result';
})
最佳答案
尝试:
<form onsubmit="monthDiff(this); return false;">
<br>month 1<input id="m1" value="1">
year 1<input id="y1" value="2010">
<br>month 2<input id="m2" value="3">
year 2<input id="y2" value="2010">
<br>Difference in months:<input id="diff">
<br><input type="submit">
</form>
<script>
function monthDiff(f) {
f.diff.value = f.y2.value * 12 + Number(f.m2.value) -
f.y1.value * 12 - f.m1.value;
}
</script>
关于javascript - 如何在jQuery中计算两个日期之间的月份? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8227102/