最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Select2 example is not working - Stack Overflow

programmeradmin1浏览0评论

I am trying to use Select2.js plugin. I have created a fiddle of the simplest example of select2 but i can't figure out why this is not working ?

you can see in the fiddle that selection of items in selectlist and allow clear is not working.

Can anybody please help me, what i am doing wrong here ?

I am trying to use Select2.js plugin. I have created a fiddle of the simplest example of select2 but i can't figure out why this is not working ?

http://jsbin.com/edeseh/2/edit

you can see in the fiddle that selection of items in selectlist and allow clear is not working.

Can anybody please help me, what i am doing wrong here ?

Share Improve this question edited Apr 1, 2013 at 18:39 Gaurav 8,48714 gold badges57 silver badges91 bronze badges asked Apr 1, 2013 at 17:45 user1740381user1740381 2,1999 gold badges40 silver badges62 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 11

You should use options value to enable selection

and

you should use an empty option for showing placeholder and allowClear option.

Here is the working fiddle :

http://jsbin.com/edeseh/8/edit

Main code copied from the link:

HTML:

<select id="e2" style="width:200px;">
  <option value=""><option>
  <option value="1">Mustard</option>
  <option value="2">Ketchup</option>
  <option value="3">Relish</option>
</select>

JavaScript:

$("#e2").select2({
  placeholder: "Select a State",
  allowClear: true
});

Older versions require you to add 'select2' class in the dropdown.

发布评论

评论列表(0)

  1. 暂无评论