When use multiple selector, Uncaught SyntaxError: Invalid or unexpected token

When use multiple selector, Uncaught SyntaxError: Invalid or unexpected token

我明白了 error.I 想添加多个选择器,它给出了 error.what 是问题吗?

 jQuery(document).ready(function($) {
            $("nav.navbar.bootsnav.menu-style1 ul.dropdown-menu.megamenu-content .title,
                .pagination>li>a,
                .ulockd-title-icon,
    .fancybox-gallery-slider .owl-prev,
    .fancybox-gallery-slider .owl-next,
    .team-icon a,
    .twitter.style2 ul li a,
    .text-thm, .text-thm2").css("color", textColor);;
            return false;
    });

您可以通过多种方式解决此错误:

在每个换行符前使用\

$("nav.navbar.bootsnav.menu-style1 ul.dropdown-menu.megamenu-content .title, \
    .pagination>li>a, \
    .ulockd-title-icon, \
    .fancybox-gallery-slider .owl-prev, \
    .fancybox-gallery-slider .owl-next, \
    .team-icon a, \
    .twitter.style2 ul li a, \
    .text-thm, .text-thm2").css("color", textColor);

使用字符串连接

$("nav.navbar.bootsnav.menu-style1 ul.dropdown-menu.megamenu-content .title,"
  + ".pagination>li>a,"
  + ".ulockd-title-icon,"
  + ".fancybox-gallery-slider .owl-prev,"
  + ".fancybox-gallery-slider .owl-next,"
  + ".team-icon a,"
  + ".twitter.style2 ul li a,"
  + ".text-thm,"
  + ".text-thm2").css("color", textColor);

从数组构建 selector

let selectors = [
  "nav.navbar.bootsnav.menu-style1 ul.dropdown-menu.megamenu-content .title",
  ".pagination>li>a",
  ".ulockd-title-icon",
  ".fancybox-gallery-slider .owl-prev",
  ".fancybox-gallery-slider .owl-next",
  ".team-icon a",
  ".twitter.style2 ul li a",
  ".text-thm",
  ".text-thm2"
];
$(selectors.join(',')).css("color", textColor);

使用模板文字

$(`nav.navbar.bootsnav.menu-style1 ul.dropdown-menu.megamenu-content .title,
    .pagination>li>a,
    .ulockd-title-icon,
    .fancybox-gallery-slider .owl-prev,
    .fancybox-gallery-slider .owl-next,
    .team-icon a,
    .twitter.style2 ul li a,
    .text-thm, .text-thm2`).css("color", textColor);

或者给他们一个普通的class

如您所见,有很多这样的 selector 不容易使用。更不用说随着时间的推移管理变化。

为什么不给他们一个常见的 class,比如 changeable-color,而且只给 select 那个。更易于阅读和维护。