(已解决)SyntaxError: Failed to execute ‘querySelector’ on ‘Document’: “xxx” is

829 阅读1分钟

SyntaxError: Failed to execute ‘querySelector’ on ‘Document’: “xxx” is not a valid selector."

原因:

  • 出现如上报错是因为我使用了字母开头的字符串作为id

解决:

  • querySelector没办法识别以数字开头命名的id,将querySelector改成getElementById()即可