HTML Select beautify analog jquery plugin Select2.js

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.