最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to trigger a date input's calendar on double click? - Stack Overflow

programmeradmin1浏览0评论

I am trying to trigger the <input type="date"> calendar to be shown on a double click event, like a user was clicking on the arrow in the right, but with no success, because I could not identify how the browser implements it. (Chrome 56.0.2924.87).

Anyone have an idea if it's possible, and if so how I can do this?

<input type="date">

I am trying to trigger the <input type="date"> calendar to be shown on a double click event, like a user was clicking on the arrow in the right, but with no success, because I could not identify how the browser implements it. (Chrome 56.0.2924.87).

Anyone have an idea if it's possible, and if so how I can do this?

<input type="date">

Share Improve this question edited Apr 18, 2022 at 15:39 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Mar 31, 2017 at 15:17 IsraelIsrael 211 silver badge2 bronze badges 4
  • Did you try Jquery's prevent.default ? – oneNiceFriend Commented Mar 31, 2017 at 15:21
  • In chrome you can access using input::-webkit-calendar-picker-indicator, I do not know if you can trigger click for that element $('input::-webkit-calendar-picker-indicator').click() Just in case take a look at this question stackoverflow./questions/14946091/… – Miguel Lattuada Commented Mar 31, 2017 at 15:32
  • I've tried $('input::-webkit-calendar-picker-indicator').click() and $('#elementid::-webkit-calendar-picker-indicator').click() but it didn't worked. – Israel Commented Mar 31, 2017 at 15:49
  • How should I use prevent.default in this case? I've not understood where to use it and how the calendar would be shown doing this. – Israel Commented Mar 31, 2017 at 15:51
Add a ment  | 

1 Answer 1

Reset to default 6

I found a better way that works across browsers.

The only negative is you don't get to see the icon.

The idea is to set the date input as relative and then absolutely position the datepicker icon to span the entire input, and set its opacity to 0 so it's not visible.

This triggers the datepicker across browsers when you click the input.

Code:

/* date styles */
.datepicker {
  position: relative;
  cursor: pointer;
  box-sizing: border-box;
  line-height: normal !important;
}
.datepicker::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
发布评论

评论列表(0)

  1. 暂无评论