freejs首页

select各种效果:select带搜索框 多个option项目选择

Standard Select

标准select
Into This
选择省份
  • 北京
  • 上海
  • 重庆
  • 天津
  • 湖北
  • 湖南
  • 广东
  • 浙江

多选

Turns This
Into This
  • 北京
  • 上海
  • 重庆
  • 天津
  • 湖北
  • 湖南
  • 广东
  • 浙江

<optgroup> Support

Single Select with Groups
Your Favorite Football Team
  • NFC EAST
  • Dallas Cowboys
  • New York Giants
  • Philadelphia Eagles
  • Washington Redskins
  • NFC NORTH
  • Chicago Bears
  • Detroit Lions
  • Green Bay Packers
  • Minnesota Vikings
  • NFC SOUTH
  • Atlanta Falcons
  • Carolina Panthers
  • New Orleans Saints
  • Tampa Bay Buccaneers
  • NFC WEST
  • Arizona Cardinals
  • St. Louis Rams
  • San Francisco 49ers
  • Seattle Seahawks
  • AFC EAST
  • Buffalo Bills
  • Miami Dolphins
  • New England Patriots
  • New York Jets
  • AFC NORTH
  • Baltimore Ravens
  • Cincinnati Bengals
  • Cleveland Browns
  • Pittsburgh Steelers
  • AFC SOUTH
  • Houston Texans
  • Indianapolis Colts
  • Jacksonville Jaguars
  • Tennessee Titans
  • AFC WEST
  • Denver Broncos
  • Kansas City Chiefs
  • Oakland Raiders
  • San Diego Chargers
Multiple Select with Groups
  • NFC EAST
  • Dallas Cowboys
  • New York Giants
  • Philadelphia Eagles
  • Washington Redskins
  • NFC NORTH
  • Chicago Bears
  • Detroit Lions
  • Green Bay Packers
  • Minnesota Vikings
  • NFC SOUTH
  • Atlanta Falcons
  • Carolina Panthers
  • New Orleans Saints
  • Tampa Bay Buccaneers
  • NFC WEST
  • Arizona Cardinals
  • St. Louis Rams
  • San Francisco 49ers
  • Seattle Seahawks
  • AFC EAST
  • Buffalo Bills
  • Miami Dolphins
  • New England Patriots
  • New York Jets
  • AFC NORTH
  • Baltimore Ravens
  • Cincinnati Bengals
  • Cleveland Browns
  • Pittsburgh Steelers
  • AFC SOUTH
  • Houston Texans
  • Indianapolis Colts
  • Jacksonville Jaguars
  • Tennessee Titans
  • AFC WEST
  • Denver Broncos
  • Kansas City Chiefs
  • Oakland Raiders
  • San Diego Chargers

Selected and Disabled Support

Chosen automatically highlights selected options and removes disabled options.

Single Select
Sloth Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Polar Bear
Multiple Select
  • Sloth Bear
  • Polar Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Polar Bear

Hide Search on Single Select

The disable_search_threshold option can be specified to hide the search input on single selects if there are fewer than (n) options.

$(".chosen-select").chosen({disable_search_threshold: 10});

Polar Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Polar Bear

Default Text Support

Chosen automatically sets the default field text ("选择省份") by reading the select element's data-placeholder value. If no data-placeholder value is present, it will default to "Select an Option" or "Select Some Options" depending on whether the select is single or multiple. You can change these elements in the plugin js file as you see fit.

<select data-placeholder="选择省份" style="width:350px;" multiple class="chosen-select">

Note: on single selects, the first element is assumed to be selected by the browser. To take advantage of the default text support, you will need to include a blank option as the first element of your select list.

No Results Text Support

Setting the "No results" search text is as easy as passing an option when you create Chosen:

 $(".chosen-select").chosen({no_results_text: "Oops, nothing found!"}); 

Single Select
Type 'C' to view
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear
Multiple Select
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear

Limit Selected Options in Multiselect

You can easily limit how many options the user can select:

$(".chosen-select").chosen({max_selected_options: 5});

If you try to select another option with limit reached chosen:maxselected event is triggered:

 $(".chosen-select").bind("chosen:maxselected", function () { ... }); 

Allow Deselect on Single Selects

When a single select box isn't a required field, you can set allow_single_deselect: true and Chosen will add a UI element for option deselection. This will only work if the first option has blank text.

Sloth Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear

Right to Left Support

Chosen supports right to left select boxes too. just add "chosen-rtl" in addition to "chosen-select" to your select tags and you are good to go.

<select class="chosen-select chosen-rtl">
Single right to left select
Sloth Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Polar Bear
Multiple right to left select
  • Sloth Bear
  • Polar Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Polar Bear

Change / Update Events

  • Form Field Change

    When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event* on the original form field. That let's you do something like this:

    $("#form_field").chosen().change();
  • Updating Chosen Dynamically

    If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "chosen:updated" event on the field. Chosen will re-build itself based on the updated content.

    $("#form_field").trigger("chosen:updated");

Custom Width Support

Using a custom width with Chosen is as easy as passing an option when you create Chosen:

 $(".chosen-select").chosen({width: "95%"}); 
Single Select
American Black Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear
Multiple Select
  • Giant Panda
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear

Labels work, too

Use labels just like you would a standard select

American Black Bear
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear
  • Giant Panda
  • American Black Bear
  • Asiatic Black Bear
  • Brown Bear
  • Giant Panda
  • Sloth Bear
  • Sun Bear
  • Polar Bear
  • Spectacled Bear