function TimeVerify(sender, args) { var startTime = document.getElementById('<%= tbStartTime.ClientID%>').value.split("-"); var endTime = document.getElementById('<%= tbEndTime.ClientID%>').value.split("-"); var st = new Date(startTime[0], startTime[1], startTime[2]); var et = new Date(endTime[0], endTime[1], endTime[2]); if (st.getTime() > et.getTime()) { args.IsValid = false; } else { args.IsValid = true; } }
验证控件:
<asp:CustomValidator ID="cvTime" Display="None" runat="server" ErrorMessage="开始时间不能大于结束时间!" ClientValidationFunction="TimeVerify"></asp:CustomValidator>