我正在使用 select2。内置事件不支持所选项目上的悬停事件,因此我尝试在鼠标悬停在该项目上时触发悬停事件(多项选择)。
function tagFormat(state) {
return '<span class="tagElement">' + state.text + '</span>';
}
$('.tagElement').hover(function(event){
alert('something');
});
var sampleTags = ['red','white'];
$("[taggable]").select2({
formatSelection: tagFormat,
maximumInputLength: 10,
tags:sampleTags,
tokenSeparators: [",", " "]
});
引导层位于http://bootply.com/96527,您可以看到在 select2 外部,悬停事件确实会触发,但在 select2 内部却不会。里面的机制是什么?
select2.js 有一个函数 .show,每当您将鼠标悬停在选项上时,它都会更新属性“aria-descriptedby”。这个功能可以扩展...
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);
}
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)