admin管理员组文章数量:1344938
I need to add a Button to every select2 item and prevent the default event so only the button gets triggered.
I have the following code but the normal onSelect
event still gets triggered:
select.on('select2:select', test2);
function test2(e) {
if (e.params.originalEvent.target.classList.contains('TreeButton')) {
//stop event execution
e.stopPropagation();
e.preventDefault();
return false;
} else {
//execute normal
}
}
I need to add a Button to every select2 item and prevent the default event so only the button gets triggered.
I have the following code but the normal onSelect
event still gets triggered:
select.on('select2:select', test2);
function test2(e) {
if (e.params.originalEvent.target.classList.contains('TreeButton')) {
//stop event execution
e.stopPropagation();
e.preventDefault();
return false;
} else {
//execute normal
}
}
Share
Improve this question
edited Jan 3, 2018 at 18:11
beaver
17.7k2 gold badges43 silver badges68 bronze badges
asked Jan 3, 2018 at 14:49
TiDiTiDi
631 silver badge4 bronze badges
1 Answer
Reset to default 10Try to catch select2:selecting
event:
select.on("select2:selecting", function (e) {
if (e.params.args.originalEvent.target.className === 'btn') {
e.preventDefault();
}
}
Here is a jsfiddle: http://jsfiddle/beaver71/dtjhpnm7/
本文标签: javascriptSelect2 cancelpreventDefault select2select at specific condition (v40x)Stack Overflow
版权声明:本文标题:javascript - Select2 cancelpreventDefault select2:select at specific condition (v.4.0.x) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743796688a2540561.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论