gpt4 book ai didi

javascript - element.valueAsDate = xxx - 不再工作......(javascript)

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:52:50 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个为特定日期设置默认值的 javascript。执行此操作的函数如下所示:

<script language='javascript'> 
setNow(document.getElementById('date_86')); //line 166
setNow(document.getElementById('time_86'));
setNow(document.getElementById('date_0'));
setNow(document.getElementById('time_0'));

function setNow(element) { //line 173
date = new Date();date.setHours(date.getHours() + 3);
element.valueAsDate = date;
}
...
</script>

html:

<input type='date' id='date_86' name='date_86' />

有趣的是,直到最近它还可以工作,但现在不行了,Chrome 的控制台显示:

Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
setNowmanual.html:173
(anonymous function)manual.html:166

如果我正确理解 this 的含义,我真的不明白为什么 setNow 不是这个 DOM 中的对象。

PS:当我交换声明和调用时发生同样的事情,只是控制台报告中的行号不同。

最佳答案

该死的!来自 Chromium 博客的引述 ( source )

Hi everyone, We disabled the following input types, and Google Chrome 16 isn't going to have them. date, datetime, datetime-local, month, time, and week. These types have had simple textfield interfaces with spin buttons. Since Google Chrome 16, they are not recognized as valid input types, and work as type=text. They were disabled because of their incompleteness. Their user-interfaces were not satisfying, and the existence of these types were harmfull for feature detection. We'll enable them again when we complete to implement their rich user-interfaces. -- TAMURA, Kent Software Engineer, Google

关于javascript - element.valueAsDate = xxx - 不再工作......(javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8642921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com