我有几个 div 包含两个类,例如:
<div class="dateNumbers"></div>
<div class="dateNumbers {{month.year + '-' + month.monthName + '-' + 'end'}}"></div>
<div class="dateNumbers {{month.year + '-' + month.monthName + '-' + 'end'}}"></div>
<div class="dateNumbers {{month.year + '-' + month.monthName + '-' + 'end'}}"></div>
Run Code Online (Sandbox Code Playgroud)
{{month.year + '-' + month.monthName + '-' + 'end'}}某个月份在哪里2018-August-end
我想选择仅包含2018-August-end我存储到变量中的 div,所以我尝试了这样的操作
var dataName = `2018-August-end`; // this is dynamic but for this example I have it static
document.querySelectorAll( "." + dataName);
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
未捕获的 DOMException:无法在“文档”上执行“querySelectorAll”:“.2018-August-end”不是有效的选择器。在 :1:10
这是为什么 ?
谢谢