jquery 日期和时间的逻辑,比较大小

HTML:
<ul>
<li>
<span>到达</span>
<img class="date-s" src="/public/test/img/date0.png" alt="" onclick="$('#date').focus();"
data-field="datetime"/>
<ul>
<li class="time-s" data-date="start">9:00</li>
<li class="time-e" data-date="start">2016.12.7</li>
</ul>
</li>
<li>
<span>出发</span>
<img class="date-e" src="/public/test/img/date0.png" alt="" onclick="$('#date').focus();"
data-field="datetime"/>
<ul>
<li class="time-s" data-date="end">21:00</li>
<li class="time-e" data-date="end">2016.12.7</li>
</ul>
</li>
</ul>

JQery:
$('[name="desc"]').focus(function(){
var s1= $(' ul li:first-child ul li:first-child').text();
var s2=$(' ul li:last-child ul li:first-child').text();
var a1=$(' ul li:first-child ul li:last-child').text();
var start=new Date(a1.replace("-", "/").replace("-", "/"));
var a2=$(' ul li:last-child ul li:last-child').text();
var end=new Date(a2.replace("-", "/").replace("-", "/"));
if(start>end){
alert("日期选择有误");
return false;
}
if((a1==a2)&&(s1>s2)){
alert("时间选择有误");
return false;
}
});
 
posted @ 2016-09-21 14:08  薄小冰  阅读(2296)  评论(0编辑  收藏  举报