Code Show: http://www.51xuediannao.com/demo.php
Code Description:
Select2.js is an HTML select landscaping simulation -like jquery plugin , But Select2.js is far from simple simulation beautification so simple, it also has the search function, multi-select function (can limit the number of choices), the Ajax way to load the data, you can set the placeholder,
You can set the disabled state disabled, and the settings are very simple, such as: $ (". js-example-disabled"). Prop ("disabled", false);
Select2.js Default Value setting: $ ("#select2"). Val ("1"). Trigger ("change"); The default value for multiple selections can be used for $ ("#select2"). Val (["1", "2"]). Trigger ("change"); This passes the array past.
Select2 also has a rich range of custom events
$ ("#select2"). On ("Select2:open", function (e) {log ("Select2:open", e);}); $ ("#select2"). On ("Select2:close", function (e) {log ("Select2:close", e);}); $ ("#select2"). On ("Select2:select", function (e) {log ("Select2:select", e);}); $ ("#select2"). On ("Select2:unselect", function (e) {log ("Select2:unselect", e);}); $ ("#select2"). On (' Change ', function (e) {log ("change");});
For more extensive select2 usage please refer to https://select2.github.io/examples.html, as well as some examples of practical applications, and some handy tricks for easy invocation.
Select2 Gimmick: Define the currently selected selected value, we give a <select class= "test1" on Select2 nodedata-selected= "2" > Look at the Red section, then we can use the following JS code when the setting is selected$ ("#select2"). Val (function () {return $ (this). Data ("selected")}). Trigger ("change");
Use Val () to receive a function, and you can take advantage of this
HTML Select beautify analog jquery plugin Select2.js