JQuery 判斷起始日期與結束日期大小
阿新 • • 發佈:2019-02-18
//判斷起始日期與結束日期大小
function ckdate() {
var endtime = $('#txtStorageTimeEnd').val();
var starttime = $('#txtStorageTimeStart').val();
var start = new Date(starttime.replace("-", "/").replace("-", "/"));
var end = new Date(endtime.replace("-", "/").replace("-", "/"));
if (end < start) {
alert('結束日期不能小於開始日期!');
return false;
}
else {
return true;
}
function ckdate() {
var endtime = $('#txtStorageTimeEnd').val();
var starttime = $('#txtStorageTimeStart').val();
var start = new Date(starttime.replace("-", "/").replace("-", "/"));
var end = new Date(endtime.replace("-", "/").replace("-", "/"));
if (end < start) {
alert('結束日期不能小於開始日期!');
return false;
}
else {
return true;
}
}
<asp:TextBox ID="txtStorageTimeStart" runat="server" onclick="setday(this,false)" ></asp:TextBox>
到
<asp:TextBox ID="txtStorageTimeEnd" runat="server" onclick="setday(this,false)" ></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="查詢" onclick="btnSearch_Click" OnClientClick="ckdate()" />