尝试使用 querySelectorAll 但失败

Tried to use querySelectorAll but failed

我想要 select 第一个 id 有 class a.

<li class="a" id="1">1</li>
<li class="a" id="2">2</li>
<li class="a" id="3">3</li>
var c = document.querySelectorAll(".a#1");
c.remove();

我使用 querySelectorAll 但出现

错误
Uncaught SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '.a #1' is not a valid selector.

我知道在 jquery 中它是像 $('.a#1').remove() 那样完成的并且它会工作 但我使用的是 zepto,所以我必须弄清楚纯js.

带号码的ID名称无效,但您可以如下查询

document.querySelector('.a#\31');

If the first character of an identifier is numeric, you’ll need to escape it based on its Unicode code point. For example, the code point for the character 1 is U+0031, so you would escape it as [=11=]0031 or .

有关详细信息,请参阅此 Using querySelector with IDs that are numbers