JS实现日期加减的方法

效果:成型日期-龄期=要求试验日期!

事件:

当改变成型日期文本框后触发事件!
当改变龄期文本框后触发事件!
代码:
(说明:成型日期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>

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com