Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试访问几个 html 元素的数据属性('maxselection'),同时将它们附加到 jquery 插件:
$(".select2").select2({ // several html elements maximumSelectionSize: $(this).data('maxselection') });
那是行不通的。
你如何才能达到这个特定范围内的元素属性?
顺便说一句:select2 是一个下拉增强器,一个选择的分支
this不是对象字面量定义中的选定元素。像这样的东西会起作用:
this
$(".select2").each(function () { var $this = $(this); $this.select2({ maximumSelectionSize: $this.data('maxselection'); }); });