var d = new Date()
//取当前年月日,舍去时分秒
d = new Date(d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())
var d2 = new Date(document.getElementById("txtDate").value)
if (d2 == "Invalid Date") {
alert("非日期")
return
}
//getTime 从1970.1.1开始的毫秒数
var n = d.getTime() - d2.getTime()
if (n == 0) {
alert("相等")
} else if (n >0) {
alert("小于当前日期")
} else {
alert("大于当前日期")
}
}
<input id="txtDate" type="text" value="2013-1-17"/>
<input type="button" value="比较" onclick="check()"/>
还是很简答的//最小值
Array.prototype.min = function() {
var min = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] <min){
min = this[i]
}
}
return min
}
//最大值
Array.prototype.max = function() {
var max = this[0]
var len = this.length
for (var i = 1i <leni++){
if (this[i] >max) {
max = this[i]
}
}
return max
}
希望对你有帮助