placeholders.html 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <section>
  2. <h1 id="placeholders">Placeholders</h1>
  3. <p>
  4. A placeholder value can be defined and will be displayed until a
  5. selection is made. Select2 uses the <code>placeholder</code> attribute
  6. on multiple select boxes, which requires IE 10+. You can support it in
  7. older versions with
  8. <a href="https://github.com/jamesallardice/Placeholders.js">the Placeholders.js polyfill</a>.
  9. </p>
  10. <div class="s2-example">
  11. <p>
  12. <select class="js-example-placeholder-single js-states form-control">
  13. <option></option>
  14. </select>
  15. </p>
  16. <p>
  17. <select class="js-example-placeholder-multiple js-states form-control" multiple="multiple"></select>
  18. </p>
  19. </div>
  20. <pre data-fill-from=".js-code-placeholder"></pre>
  21. <script type="text/javascript" class="js-code-placeholder">
  22. $(".js-example-placeholder-single").select2({
  23. placeholder: "Select a state",
  24. allowClear: true
  25. });
  26. $(".js-example-placeholder-multiple").select2({
  27. placeholder: "Select a state"
  28. });
  29. </script>
  30. </section>