(初学者可能不知道,可以到weui官网下载)需要引用datetimePicker.js
$('.start-time').click(function(event) {
var n = $(this),
t = v.endTime.split("/"),
id = "datePicker1";
setTime(n,t,id);
});
$('.end-time').click(function(event) {
var n = $(this),
t = v.endTime.split("/"),
id = "datePicker2";
setTime(n,t,id);
});
function setTime(n,t,id){
weui.datePicker({
start: "2001-12-29",
end: new Date(),
defaultValue: t,
onChange: function() {},
onConfirm: function(t) {
var i = t[0].value
, r = t[1].value
, u = t[2].value;
if(n.hasClass("start-time")){
v.startTime = i + "/" + fmTime(r) + "/" + fmTime(u);
n.data("time", v.startTime).text(i + " / " + fmTime(r) + " / " + fmTime(u));
}else{
v.endTime = i + "/" + fmTime(r) + "/" + fmTime(u);
n.data("time", v.endTime).text(i + " / " + fmTime(r) + " / " + fmTime(u));
}
var s1 = new Date(v.startTime),
s2 = new Date(v.endTime);
var days = s2.getTime() - s1.getTime();
var time = parseInt(days / (1000 * 60 * 60 * 24));
console.log(v);
if(time>=0&&time<=31){
console.log("通过",time)
$(".loading").removeClass("hidden");
$(".potential-agency-cells").html("");
showFun();
}else if(time<0){
$(".loading").addClass("hidden");
weui.alert("结束时间不能小于开始时间");
}
else{
console.log("不通过",time)
$(".loading").addClass("hidden");
weui.alert("时间相差不能超过31天");
}
},
id: id
});
}