当前位置: 首页 > 工具软件 > DateBox > 使用案例 >

jquery 获取datebox_jquery改变 datebox改变另一个datebox的值

郑琦
2023-12-01

//改变购买日期改变年检日期

$(function () {

$("#txtPurchaseTime").datebox({

onSelect: function () {

//获取购买日期

var PurchaseTime = $("#txtPurchaseTime").datebox('getValue');

//如果购买日期为空,不用执行后续代码

if (PurchaseTime == "" || PurchaseTime == undefined) {

return;

}

//获取保险使用性质

var InsuranceNat = $("#InsuranceNat").val();

//租赁:年检日期=购买日期+1年;非营运:年检日期=购买日期+2年

switch (InsuranceNat) {

case "租赁":

//年检日期+1年

var tmp = new Date(Date.parse(PurchaseTime.replace(/-/g, "/")));

var y = tmp.getFullYear() + 1;

var m = tmp.getMonth()+1; //月份以数组存储0-11存储,需加1得到正确的月份

var d = tmp.getDate();

var InspectionDate = y + "-" + m + "-" + d;

$("#txtInspectionDate").datebox("setValue", InspectionDate);

break;

case "非营运":

//年检日期+2年

var tmp = new Date(Date.parse(PurchaseTime.replace(/-/g, "/")));

var y = tmp.getFullYear() + 2;

var m = tmp.getMonth()+1; //月份以数组存储0-11存储,需加1得到正确的月份

var d = tmp.getDate();

var InspectionDate = y + "-" + m + "-" + d;

$("#txtInspectionDate").datebox("setValue", InspectionDate);

break;

}

}

})

})

//改变保险使用性质改变年检日期

$("#InsuranceNat").change(function () {

//获取购买日期

var PurchaseTime = $("#txtPurchaseTime").datebox('getValue');

//如果购买日期为空,不用执行后续代码

if (PurchaseTime == "" || PurchaseTime == undefined) {

return;

}

//获取保险使用性质

var InsuranceNat = $("#InsuranceNat").val();

//租赁:年检日期=购买日期+1年;非营运:年检日期=购买日期+2年

switch (InsuranceNat) {

case "租赁":

//年检日期+1年

var tmp = new Date(Date.parse(PurchaseTime.replace(/-/g, "/")));

var y = tmp.getFullYear() + 1;

var m = tmp.getMonth() + 1; //月份以数组存储0-11存储,需加1得到正确的月份

var d = tmp.getDate();

var InspectionDate = y + "-" + m + "-" + d;

$("#txtInspectionDate").datebox("setValue", InspectionDate);

break;

case "非营运":

//年检日期+2年

var tmp = new Date(Date.parse(PurchaseTime.replace(/-/g, "/")));

var y = tmp.getFullYear() + 2;

var m = tmp.getMonth() + 1; //月份以数组存储0-11存储,需加1得到正确的月份

var d = tmp.getDate();

var InspectionDate = y + "-" + m + "-" + d;

$("#txtInspectionDate").datebox("setValue", InspectionDate);

break;

}

});

})

 类似资料: