Setdate intel XDK bootstrap3输入类型日期

时间:2016-06-12 21:54:36

标签: intel-xdk

我要做的是在datepicker中选择week1的日期,然后调用函数mydateset(wk),在week2输入中设置日期加7天。

我的代码:

<input class="wide-control form-control default" type="date" id="week1"       style="font-weight: bold;" onblur="mydateset('week1')">
<input class="wide-control form-control default" type="date" id="week2"   style="font-weight: bold;">

<script>

    function mydateset(wk) {
        if (wk == 'week1') {
            var tt = document.getElementById('week1').value;
            window.alert("tt is = "+ tt );              
        }
        var ndate = new Date(tt);
        window.alert("date is = "+ ndate);
        var newdate = new Date(ndate);
        window.alert("newdate is = "+ newdate);
        newdate.setDate(newdate.getDate() + 8);

        var dd = newdate.getDate();
        var mm = newdate.getMonth() + 1;
        var y = newdate.getFullYear();

        var someFormattedDate = dd +'/' +mm + '/' + y;
        window.alert("(New date is = "+someFormattedDate );
        //document.getElementById('week2').value = someFormattedDate;
        $('#week2').val(someFormattedDate);
    }

</script>

1 个答案:

答案 0 :(得分:0)

如果不是10,我必须用0填充日期和月份变量。我必须格式化字符串&#34; yyyy-mm-dd&#34;对于datepicker来接受日期。