简体   繁体   English

打开 HTML5 日期选择器在输入框内点击

[英]Open HTML5 date picker inside input box click

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.我正在尝试使用以下代码在输入文本框中单击时打开 HTML5 日期选择器,但它没有按预期工作。

However, clicking on the calendar icon does open the date picker (by default).但是,单击日历图标会打开日期选择器(默认情况下)。 This is inside my Angular 7 application.这是在我的 Angular 7 应用程序中。

Fiddle: https://jsfiddle.net/mailmrmanoj/rL1ecp9w/5/小提琴: https://jsfiddle.net/mailmrmanoj/rL1ecp9w/5/

HTML: HTML:

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

Typescript: 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日期选择器参考: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_input_date

Try with input type="text" instead of type="date" and on focus event call function "openDP".尝试输入type="text"而不是type="date"并在焦点事件上调用 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).注意:您也可以使用 angularjs-datepicker 代替默认的 HTML5 日期选择器,因为 Safari 或 Internet Explorer 11(或更早版本)不支持type="date"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM