我正在尝试从输入的 html5 数据属性中读取一个集合,该集合被转换为 select2 以创建标签。
当我有一个输入时,这是有效的:
$(".tags").select2(
width: '220px'
tags: $(".tags").data('collection')
)
但我想使用元素本身的数据更安全,我尝试了以下方法:
$(".tags").select2(
width: '220px'
tags: $(this).data('collection')
)
但它失败并出现错误:
Uncaught query function not defined for Select2 investigador_aplicaciones
您知道是否可以将元素本身与 $(this) 这样的特定选择器一起使用?
你可以这样做:
$(".tags").each(function(){
var $this = $(this);
$this.select2({
width: '220px',
tags: $this.data('collection')
});
});
因为在您通话期间this
不代表选择器中的元素。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)