Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

html - Console.log error when clicking an input type="date"

Im using HTML5 and adding an input with a type="date" for date picker but when i have developer tools open, everytime i click in my input i get the following error displayed.

Uncaught DOMException: Failed to set the 'selectionEnd' property on 'HTMLInputElement': The input element's type ('date') does not support selection

Although it's not causing an issue to the user, ideally I don't want the error and was wondering if anyone has come across this and how to fix it.

This is my HTML:

<input id="startDate" class="form-control text-uppercase" type="date" />

Sceenshot of my console.log enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's an answer to a related question here.

Essentially, Chrome is not currently supporting selection for inputs except the text, search, tel, url, and password types. You are triggering selectionEnd by clicking into the input; there's nothing wrong with your code.

The current suggested workaround is to set your input's type to text and use the pattern attribute to ensure valid input although that will not allow you to use the browser-provided date picker if one exists.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...