[英]setSelectionRange for input type=“time”
I have a dialog box that has an HTML5 input field with a type="time"
in it.我有一个对话框,其中有一个带有type="time"
的 HTML5 输入字段。
When the dialog appears, I want to default the editing to the "minutes" portion of the dialog.当对话框出现时,我想默认编辑对话框的“分钟”部分。 I can't see a way to do it.我看不出有什么办法做到这一点。
Here is a jsFiddle example that tries to use:这是一个尝试使用的jsFiddle示例:
$("#t")[0].setSelectionRange(3, 5);
to no avail.无济于事。
Is there a way to do this?有没有办法做到这一点?
NOTE: the w3c spec here specifically has this quote:注意: 这里的 w3c 规范特别引用了这个引用:
The following IDL attributes and methods do not apply to the element: checked, files, selectionStart, selectionEnd, and selectionDirection IDL attributes;以下 IDL 属性和方法不适用于元素:checked、files、selectionStart、selectionEnd 和 selectionDirection IDL 属性; select(), setRangeText(), and setSelectionRange() methods. select()、setRangeText() 和 setSelectionRange() 方法。
Which might mean this simply isn't possible.这可能意味着这根本不可能。
NOTE 2: Chrome throws this error when attempting to call this method.注意 2:Chrome 在尝试调用此方法时会抛出此错误。 Other browsers may throw different errors:其他浏览器可能会抛出不同的错误:
Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.未捕获的 InvalidStateError:尝试使用不可用或不再可用的对象。
只需使用一些js设置它。
document.getElementsByTagName("INPUT")[0].value = "13:24"
<input type="time" id="appt" name="appt" min="09:00" max="18:00" required>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.