admin管理员组文章数量:1360375
In my application i have a javascript that sets the default values for certain dates. The function that does this looks like this:
<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' />
The funny thing is that until quite recently it used to work, but now it doesn't, and Chrome's console says:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
setNowmanual.html:173
(anonymous function)manual.html:166
I can't really see why setNow is not an object in this DOM, if I understand the meaning of this correctly.
PS: Happens the same thing when i swap the declaration and the call, only the line numbers are different in the console report.
In my application i have a javascript that sets the default values for certain dates. The function that does this looks like this:
<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' />
The funny thing is that until quite recently it used to work, but now it doesn't, and Chrome's console says:
Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
setNowmanual.html:173
(anonymous function)manual.html:166
I can't really see why setNow is not an object in this DOM, if I understand the meaning of this correctly.
PS: Happens the same thing when i swap the declaration and the call, only the line numbers are different in the console report.
Share Improve this question edited Dec 27, 2011 at 10:56 Esailija 140k23 gold badges279 silver badges328 bronze badges asked Dec 27, 2011 at 9:18 IbolitIbolit 9,74010 gold badges60 silver badges107 bronze badges 7- 1 Can you show us some HTML as well? – Tim Vermaelen Commented Dec 27, 2011 at 9:24
-
1
Side note: if you are using HTML5, you should change
<script language='javascript'>
to<script type="text/javascript">
. Thelanguage
attribute was already deprecated in HTML4. – Álvaro González Commented Dec 27, 2011 at 9:28 - @TimVermaelen: The page in question is quite large, which parts would be relevant? The elements that are passed as arguments to the setNow() function are declared as <input type='date' id='date_86' name='date_86' /> – Ibolit Commented Dec 27, 2011 at 9:37
- @ÁlvaroG.Vicario Why exactly is it wrong? The calls to the whole form and the calls to that function are generated by the server-side script, and when there is a date on the server side, it is inserted as the value, when it is null, it is generated by the javascript. – Ibolit Commented Dec 27, 2011 at 9:39
- @ÁlvaroG.Vicario I did change the javascript's openning tag to <script type="text/javascript"> -- didn't help either. – Ibolit Commented Dec 27, 2011 at 9:44
2 Answers
Reset to default 6Bloody hell! A quotation from Chromium blog (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 inpleteness. Their user-interfaces were not satisfying, and the existence of these types were harmfull for feature detection. We'll enable them again when we plete to implement their rich user-interfaces. -- TAMURA, Kent Software Engineer, Google
EDIT: According to what I just read here: http://www.w3/TR/html5/mon-input-element-attributes.html that error will be thrown if you try to set valueAsDate
on a control that "isn't date- or time-based", but given that your input is type="date"
I'm not sure what's going on.
EDIT 2: According to this page: https://groups.google./a/chromium/group/chromium-html5/browse_thread/thread/d1a22c42ebdf8ee4/9eb4210ce60341b1 Chrome version 16 has disabled the date and time input types and they will be treated as text.
Chrome doesn't seem to like the dot syntax for custom properties/attributes. Use .setAttribute()
instead:
// Chrome doesn't like
element.valueAsDate = date;
// So do this:
element.setAttribute("valueAsDate",date);
// And to retrieve the value:
var v = element.getAttribute("valueAsDate")
本文标签: exceptionelementvalueAsDatexxxnot working any more (javascript)Stack Overflow
版权声明:本文标题:exception - element.valueAsDate = xxx -- not working any more... (javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743899371a2558387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论