JavaScript抑制日期格式警告

JavaScript抑制日期格式警告,javascript,web,warnings,suppress-warnings,Javascript,Web,Warnings,Suppress Warnings,每当我尝试使用JavaScript重置日期输入时,如下所示: //input_id is an id of a date input document.getElementById(input_id).value = "0000-00-00"; 我在控制台中收到一条警告: The specified value "0000-00-00" does not conform to the required format, "yyyy-MM-dd". 有人知道如何抑制此警告,使其不显示吗?JS继续

每当我尝试使用JavaScript重置日期输入时,如下所示:

//input_id is an id of a date input
document.getElementById(input_id).value = "0000-00-00";
我在控制台中收到一条警告:

The specified value "0000-00-00" does not conform to the required format, "yyyy-MM-dd".
有人知道如何抑制此警告,使其不显示吗?JS继续平稳运行,但我想消除这些警告

如果您有其他方法重置日期输入(不发出警告),我将很高兴听到


提前感谢。

您将收到警告,因为年、月和日从1开始,而不是从0开始。对于所有这些值,0都是无效值。但是有一种更简单的方法来重置输入元素

您可以将该值设置为空字符串,这是初始默认值

var di = document.createElement("input");
di.type = "date";
console.log(di.value); // outputs ""
document.body.appendChild(di);

// change the value if you want

// to reset:
di.value = "";

您可以指定一个空字符串值

document.getElementById(input_id).value = "";

在Javascript调用的底部

console.clear();
这将清除控制台中的所有警告和错误

您还可以用自己的代码替换控制台。警告,如:

console.warn=function(){}

不建议这样做,因为这样您的主机将不会收到任何警告。

我认为,这与: