如何在select2选项上启用hover事件

我正在使用select2。 内置事件不支持选择项目上的hover事件,因此当鼠标hover在项目上时,我正尝试触发hover事件(多个选择)。

function tagFormat(state) { return '' + state.text + ''; } $('.tagElement').hover(function(event){ alert('something'); }); var sampleTags = ['red','white']; $("[taggable]").select2({ formatSelection: tagFormat, maximumInputLength: 10, tags:sampleTags, tokenSeparators: [",", " "] }); 

Bootply在http://bootply.com/96527 ,您可以看到在select2之外的hover事件确实会触发,但是在select2中它没有。 里面的机制是什么?

select2.js有一个函数.show,只要将鼠标hover在某个选项上,它就会更新属性“aria-describedby”。 这个function可以扩展……

jsfiddle的例子

 c.prototype.show = function() { var b = a.Event("show.bs." + this.type); this.$element.trigger(b); var d = a.contains(this.$element[0].ownerDocument.documentElement, this.$element[0]); if (b.isDefaultPrevented() || !d) return; var e = this, f = this.tip(), g = this.getUID(this.type); /*look for the select box and find the 'onmouseover' attribute */ var s = this.$element.siblings('select'); if (s != undefined && s.attr('onmouseover') != undefined) { var m = s.attr('onmouseover'); eval(m); } ... }