You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用jQuery选择同时含template-2-box和active-template类的按钮

解决方法

在jQuery中要选中同时匹配多个类的元素,直接将多个类选择器无间隔拼接即可,具体写法如下:

const targetBtn = $('.template-2-box.active-template');

说明

  • 类选择器之间没有空格代表「且」的匹配关系,即元素必须同时具备所有指定类才会被选中,完全符合你的筛选需求
  • 可通过如下代码验证选中结果是否正确:
console.log(targetBtn.attr('class'));
// 预期输出结果:template-2-box template-6 t-premium active-template

内容的提问来源于stack exchange,提问作者yobazzinga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 08:24:04