Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tags 选择2选择2已删除事件查找标记位置_Tags_Jquery Select2 - Fatal编程技术网

Tags 选择2选择2已删除事件查找标记位置

Tags 选择2选择2已删除事件查找标记位置,tags,jquery-select2,Tags,Jquery Select2,我有一个select2多标签控件(在我的情况下限制为2),其中标签的位置很重要 我正在列出select2 removed事件,并希望找到要删除的标记的位置 我可以在remove事件中中断,并检查e,但这会给我元素的id,而不是tag字段中的位置 $('#mytags').on('select2-removed', function(e){ console.log('removed', e) }); 如何确定删除了哪个标记(第一个或第二个)?当触发select2 removed事件

我有一个select2多标签控件(在我的情况下限制为2),其中标签的位置很重要

我正在列出select2 removed事件,并希望找到要删除的标记的位置

我可以在remove事件中中断,并检查e,但这会给我元素的id,而不是tag字段中的位置

$('#mytags').on('select2-removed', function(e){

     console.log('removed', e)

});

如何确定删除了哪个标记(第一个或第二个)?

当触发
select2 removed
事件时,该项已被删除,因此您无法检查当时select2控件的值。但是,您可以在
select2 removing
事件触发时进行检查。然后,如果您想要在
select2 removed
事件发生时删除项目的位置,可以将其存储在select元素上的
data
值中

$('#mytags').on('select2-removing', function(e) {
    var $select = $(this);
    $select.data('select2-removedIndex',  $select.select2('val').indexOf(e.val));
}).on('select2-removed', function(e) {
    alert($(this).data('select2-removedIndex'));
})

@crafter-你还在工作吗?