效果:成型日期-齡期=要求試驗日期!
事件:
當改變成型日期文字方塊後觸發事件!
當改變齡期文字方塊後觸發事件!
代碼:
(說明:成型日期ID: tbcxrq 齡期ID: tblq 要求試驗日期ID: tbyqsyrq)
複製代碼代碼如下:
<script type="text/javascript">
$(function() {
$("#<%=tbcxrq.ClientID %>").change(function() { CaclDate(); });
$("#<%=tblq.ClientID %>").change(function() { CaclDate(); });
//根據齡期計算試驗時間
function CaclDate() {
if ($("#<%=tblq.ClientID %>").val() == "" || $("#<%=tbcxrq.ClientID %>").val() == "") {
$("#<%=tbyqsyrq.ClientID %>").val("");
}
else {
var MoldingDate = $("#<%=tbcxrq.ClientID %>").val();
MoldingDate = MoldingDate.replace("-", "/")
var d = new Date(MoldingDate);
var AgeDate = $("#<%=tblq.ClientID %>").val();
d.setDate(d.getDate() + parseInt(AgeDate));
var month = d.getMonth() + 1;
if (parseInt(month) < 10)
month = "0" + month;
var day = d.getDate();
if (parseInt(day) < 10)
day = "0" + day;
var date = (d.getFullYear()) + "-" + month + "-" + day;
$("#<%=tbyqsyrq.ClientID %>").val(date);
}
}
});
</script>