如何在 CSS 中为 Dropkick 插件单独定位多个下拉列表

2022-01-11 00:00:00 jquery jquery-plugins javascript

跟进:如何通过修改这个制作自定义样式下拉的jQuery插件来获取相对单位而不是px的输出?

参考:http://jamielottering.github.com/DropKick/

给定以下JS:

    dropdownTemplate = [
  '<div class="dk_container" id="dk_container_{{ id }}" tabindex="{{ tabindex }}">',
    '<a class="dk_toggle">',
      '<span class="dk_label">{{ label }}</span>',
    '</a>',
    '<div class="dk_options">',
      '<ul class="dk_options_inner">',
      '</ul>',
    '</div>',
  '</div>'
].join(''),

如何分配自定义 ID 或以其他方式单独定位每个 dk_toggle 实例?我正在创建多个下拉列表,但修改宽度(每个链接问题)的唯一方法是定位 dk_toggle 类,该类没有为每个实例分配 ID.

How can I assign a custom ID or otherwise individually target each dk_toggle instance? I am creating multiple dropdowns, but the only way to modify the width (per linked question) is to target the dk_toggle class, which does not have an ID assigned to each instance.

推荐答案

DropKick 有主题,所以你可以这样做:

DropKick has themes, so you would do something like this:

$('select.a').dropkick({ theme: 'black' });
$('select.b').dropkick({ theme: 'white' });

然后按照你的风格:

.dk_theme_black { background:black; color:white;}
.dk_theme_white { background:white; color:black;}

相关文章