Open HTML5 date picker inside input box click

我与影子孤独终老i 提交于 2020-07-16 05:50:21

问题


I'm trying to open a HTML5 date picker on click inside an input text box using the below code, but it is not working as expected.

However, clicking on the calendar icon does open the date picker (by default). This is inside my Angular 7 application.

Fiddle: https://jsfiddle.net/mailmrmanoj/rL1ecp9w/5/

HTML:

<input
  type="date"
  name="startDate"
  id="datePick"
  (click)="openDP()"
  class="input--small"
/>

Typescript:

declare var $;

openDP() {           
  $('#datePick').datepicker('show');
}

Is there anything wrong with my code?

Reference for the date picker: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_date


回答1:


Try with input type="text" instead of type="date" and on focus event call function "openDP".

<input name="date" type="text" (focus)="focusFunction()" (focusout)="focusOutFunction()">

Note: You can also use angularjs-datepicker instead of default HTML5 date picker as type="date" is not supported in Safari or Internet Explorer 11 (or earlier).



来源:https://stackoverflow.com/questions/62749795/open-html5-date-picker-inside-input-box-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!