浏览器:标识符输入已经声明,但仅在wordpress上有效?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浏览器:标识符输入已经声明,但仅在wordpress上有效?相关的知识,希望对你有一定的参考价值。

我正在制作一个扩展的搜索表单,我正是在这样做...https://codepen.io/MilanMilosev/pen/JdgRpB

我制作了一个简单的html并成功了,但是我想将它放在带有在线商店的wordpress中,但是当我放置所有代码时,控制台会标记错误

未捕获的SyntaxError:标识符'input'已经被声明

这是使用的javascript

const input = document.getElementById ("search-input");
const searchBtn = document.getElementById ("search-btn");

const expand = () => {
   searchBtn.classList.toggle ("close");
   input.classList.toggle ("square");
};

searchBtn.addEventListener ("click", expand);

任何人都知道为什么会发生吗?

答案

此错误是由于使用常量引起的。

const input = document.getElementById ("search-input");

每个错误已经存在const输入的另一个实例:

未捕获的SyntaxError:标识符'input'已经被声明

您只需要重命名变量。

以上是关于浏览器:标识符输入已经声明,但仅在wordpress上有效?的主要内容,如果未能解决你的问题,请参考以下文章