Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
23
Help us understand the problem. What is going on with this article?
@kazu56

【jQuery】select2プラグイン

More than 5 years have passed since last update.

セレクトボックスに装飾を加えるプラグイン。フィルタ付きセレクトボックスや、タグ付きセレクトボックスや、画像付きセレクトボックスなどが作れる。

サイト
https://select2.github.io/

CDN

<link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/css/select2.min.css" rel="stylesheet" />

<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-rc.2/js/select2.min.js"></script>

フィルタ付きセレクトボックス

html
<select>
  <option>サッカー</option>
  <option>野球</option>
  <option>バスケ</option>
</select>
jQuery

$('select').select2({
  width:"300px",  //サイズ
  placeholder: "スポーツを選択してください", //プレースフォルダ
  allowClear: true //
})
//セレクトボックス変更時
.on('change',function(){

})

参考
Events in select2 [jQuery]
select2.jsを使用してみる
[JS]セレクトボックスの使い勝手をパワーアップするスクリプト -Select2

bootstrap2のモーダルと併用して動かなかった件

モーダルにtabindex="-1"を書くと動かないので注意。

参考:Select2 doesn't work when embedded in a bootstrap modal

23
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kazu56

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
23
Help us understand the problem. What is going on with this article?