无法设置' valueAsDate'属性' HTMLInputElement'

时间:2015-08-06 09:09:47

标签: jquery html

编辑:我正在使用这个日期选择器BTW: https://github.com/CuriousSolutions/DateTimePicker

我在HTML页面上执行此操作,它可以正常工作:

$(document).ready(function() {
var now = new Date();

now = new Date();
now.addWeeks(0);
$("#dt0weeks")[0].valueAsDate = now;    

now = new Date();
now.addWeeks(18);
$("#dt18weeks")[0].valueAsDate = now;

now = new Date();
now.addWeeks(90);
$("#dt90weeks")[0].valueAsDate = now;

now = new Date();
now.addWeeks(1);
$("#dt1weeks")[0].valueAsDate = now;

});

它可以正常工作。

但是,当我尝试做几乎相同的事情时:

    $(function() {
    $("#dt0weeks").change(function () {
        alert('I changed on you');  
        //now = new Date();
        //now.addWeeks(0);
        //$("#dt0weeks")[0].valueAsDate = now;  

        var now = new Date();

        now = new Date("2019-03-25");
        now.addWeeks(18);
        $("#dt18weeks")[0].valueAsDate = now;

        now = new Date("2015-03-25");
        now.addWeeks(90);
        $("#dt90weeks")[0].valueAsDate = now;

        now = new Date("2011-03-25");
        now.addWeeks(1);
        $("#dt1weeks")[0].valueAsDate = now;    
    });
    });

它不会工作,我收到Failed to set the 'valueAsDate' property on 'HTMLInputElement'错误,这是一张图片。我不明白为什么。 enter image description here

0 个答案:

没有答案