我在我的 jekyll 站点上使用 javascript 实现了即时搜索功能: https://cecilialee.github.io (存储库:https://github.com/cecilialee/cecilialee.github.io)
它在 Chrome 和 Firefox 上完美运行。然而,当我在 Safari 上测试它时,无论是在 Mac 还是 iPhone 上,脚本似乎都不起作用..
我能做什么?
最佳答案
好的,我找到了答案。
当我检查 Safari 时,我发现 SyntaxError: Can't create duplicate variable that shadows a global property: 'results'
。
This is apparently a problem Safari has with declaring a let/const variable that shares the same name as a selected id attribute. I had some variables declared with const as you did and got the same error. Changed to let and still got it. Changed to var and it worked.
引用: "can't create duplicate variable that shadows a global property"
因此,我更改了一些 JavaScript const 以避免与 id 重复。脚本再次发挥魅力!
关于JavaScript 不适用于 Safari(Mac 和 iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47616770/