在js里面 开始时间日期框 ID=a 结束时间日期框 ID=b 点击查询让它们自动判断开始时间不能大于结束时间 (用js 或者用jquery 都可以 在线等答案...)
3条回答 默认 最新
斯洛文尼亚旅游 2015-04-08 04:43关注你时间格式怎么样的 2014-4-8这种格式还是什么?
<form> 开始:<input type="text" id="a" />结束:<input type="text" id="b" /><input type="button" onclick="Compare()" value="比较"/> </form> <script> function Compare() { var a = document.getElementById('a'), b = document.getElementById('b'); if (a.value != '' && b.value != '') {//将2015-4-5这种格式替换为2015/4/5,Date支持这种格式数据作参数 a = new Date(a.value.replace(/-/g, '/')); b = new Date(b.value.replace(/-/g, '/')); console.log(a.getTime()) console.log(b.getTime()) if (a.getTime() > b.getTime()) { alert('开始时间不能大于结束时间!'); } } } </script>本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报