0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【初心者でもわかる】カレンダー系jsを入れた時にスマホで入力欄が邪魔なので非表示にする方法

Posted at

どうも7noteです。入力するキーパッドを非表示にする方法です。

カレンダー系のjsを入れた場合、PCで検証しただけでは特に問題なさそうですが、
実機のスマホでみると標準のキーパッドが出てしまし、カレンダーの入力がしにくくなってしまいます。


↑キーパッドが表示されて、カレンダーが見にくい。

inputのキーパッド入力を無効化する方法

この対策として、input属性にreadonly="readonly"を指定することでキーパッドがでなくなります。

index.html
<!-- キーパッドを表示させない -->
<input type="text" id="datepicker" readonly="readonly">

readonly="readonly"を指定することで、キーパッドからの入力がされなくなります。
しかし入力自体を完全に不可にしているわけではないので、jsなどでinputの値を操作することができます。

まとめ

カレンダーは基本的にjavascriptで動いているので、もしjsを無効に設定しているブラウザでは全く操作・入力ができなくなるので注意ください。

似た属性にdisabledがありますが、こちらは完全にinput自体を無効化してしまうのでsubmit等で値の送信ができません。

おそまつ!

~ Qiitaで毎日投稿中!! ~
【初心者向け】WEB制作のちょいテク詰め合わせ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?