LoginSignup
1

More than 5 years have passed since last update.

iOSでselectboxの中身が長い時に省略される問題(jsで全セレクトボックスに対応)

Last updated at Posted at 2017-07-06

【iOS】select要素内の文字列が長く、選択肢が省略されてしまう(…表示)場合の対策 - Qiita

こちらの記事を参考に、最後にこれを追加するとオッケーなのですが、全フォームに対して手作業で追加していくのは面倒です。

<optgroup label=""></optgroup>

なので、下記のように書くと勝手に追加してくれます。

$(function() {    
    var ua = navigator.userAgent;
    if (ua.indexOf('iPhone') > 0 || ua.indexOf('iPod') > 0 ) {
            var selects = document.querySelectorAll("select");
            for (var i = 0; i < selects.length; i++ ){
                selects[i].appendChild(document.createElement("optgroup"));
            }
    }
});

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
1