blob: 54a13e2ba93c0e39920e6b11511925c349f09de4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
---
title: HTMLInputElement.showPicker()
slug: Web/API/HTMLInputElement/showPicker
tags:
- API
- HTML DOM
- HTMLInputElement
- メソッド
- NeedsCompatTable
- リファレンス
browser-compat: api.HTMLInputElement.showPicker
translation_of: Web/API/HTMLInputElement/showPicker
---
{{ APIRef("HTML DOM") }}
**`HTMLInputElement.showPicker()`** メソッドは、ブラウザーのピッカーをユーザーに表示します。
ブラウザーのピッカーは、その要素が `"date"`, `"month"`, `"week"`, `"time"`, `"datetime-local"`, `"color"`, `"file"` の型のうちの何れかである場合に表示されます。これは {{htmlelement("datalist")}} 要素や [`autocomplete`](/ja/docs/Web/HTML/Attributes/autocomplete) 属性からの項目を表示することもできます。
### 返値
{{jsxref("undefined")}} です。
### 例外
- `NotAllowedError` の {{domxref("DOMException")}}
- : タッチジェスチャーやマウスクリックなどのユーザージェスチャーに応答して呼び出されなかった場合に発生します。
- `SecurityError` の {{domxref("DOMException")}}
- : 別オリジンの iframe の中で呼び出した場合に発生します。
## 構文
```js
element.showPicker();
```
## 例
この例のボタンをクリックすると、ブラウザーの日付ピッカーが表示されます。
### HTML
```html
<input type="date">
<button>日付ピッカーを表示</button>
```
### JavaScript
```js
const button = document.querySelector("button");
const dateInput = document.querySelector("input");
button.addEventListener("click", () => {
try {
dateInput.showPicker();
// 日付ピッカーが表示されます。
} catch (error) {
window.alert(error);
// 失敗した場合は外部ライブラリーを使用してください。
}
});
```
### 結果
{{EmbedLiveSample("Example")}}
## 仕様書
{{Specifications}}
## ブラウザーの互換性
{{Compat}}
## 関連情報
- {{ HTMLElement("input") }}
- {{ domxref("HTMLInputElement") }}
|