Jquery未捕获语法错误。用于测试文件,但不用于生产。下拉引导4主题选择器

Jquery未捕获语法错误。用于测试文件,但不用于生产。下拉引导4主题选择器,jquery,twitter-bootstrap,bootstrap-4,Jquery,Twitter Bootstrap,Bootstrap 4,$(“#主题下拉”)。单击(功能(e){ 主题={ “蔚蓝”:https://bootswatch.com/4/cerulean/bootstrap.min.css', “Cosmo”:https://bootswatch.com/4/cosmo/bootstrap.min.css', “电子人”:https://bootswatch.com/4/cyborg/bootstrap.min.css', “黑暗的”:https://bootswatch.com/4/darkly/bootstrap.

$(“#主题下拉”)。单击(功能(e){
主题={
“蔚蓝”:https://bootswatch.com/4/cerulean/bootstrap.min.css',
“Cosmo”:https://bootswatch.com/4/cosmo/bootstrap.min.css',
“电子人”:https://bootswatch.com/4/cyborg/bootstrap.min.css',
“黑暗的”:https://bootswatch.com/4/darkly/bootstrap.min.css',
“断然地”:https://bootswatch.com/4/flatly/bootstrap.min.css',
“日记”:https://bootswatch.com/4/journal/bootstrap.min.css',
“文学”:https://bootswatch.com/4/litera/bootstrap.min.css',
“流明”:https://bootswatch.com/4/lumen/bootstrap.min.css',
“勒克斯”:https://bootswatch.com/4/lux/bootstrap.min.css',
“材料”:https://bootswatch.com/4/materia/bootstrap.min.css',
“薄荷糖”:https://bootswatch.com/4/minty/bootstrap.min.css',
"脉搏":"https://bootswatch.com/4/pulse/bootstrap.min.css',
“砂岩”:https://bootswatch.com/4/sandstone/bootstrap.min.css',
“单纯形”:https://bootswatch.com/4/simplex/bootstrap.min.css',
"粗略":"https://bootswatch.com/4/sketchy/bootstrap.min.css',
“板岩”:https://bootswatch.com/4/slate/bootstrap.min.css',
“太阳能”:https://bootswatch.com/4/solar/bootstrap.min.css',
“太空实验室”:https://bootswatch.com/4/spacelab/bootstrap.min.css',
“超级英雄”:https://bootswatch.com/4/superhero/bootstrap.min.css',
“联合”:https://bootswatch.com/4/united/bootstrap.min.css',
“雪人”:https://bootswatch.com/4/yeti/bootstrap.min.css',
}
变量选择=$(“#主题下拉”)
choice.text(this.innerHTML);
if(选项[0]。主题中的innerHTML){
$('#bootswatch').attr('href',themes[choice[0].innerHTML])
}
});

还有别的吗 其他一些内容


我对jQuery做了一些返工。我更改了选择器,更改了所有元素以使用
javascript:void(0)

$(“.navbar a”)。单击(函数(e){
e、 预防默认值();
主题={
“蔚蓝”:https://bootswatch.com/4/cerulean/bootstrap.min.css',
“Cosmo”:https://bootswatch.com/4/cosmo/bootstrap.min.css',
“电子人”:https://bootswatch.com/4/cyborg/bootstrap.min.css',
“黑暗的”:https://bootswatch.com/4/darkly/bootstrap.min.css',
“断然地”:https://bootswatch.com/4/flatly/bootstrap.min.css',
“日记”:https://bootswatch.com/4/journal/bootstrap.min.css',
“文学”:https://bootswatch.com/4/litera/bootstrap.min.css',
“流明”:https://bootswatch.com/4/lumen/bootstrap.min.css',
“勒克斯”:https://bootswatch.com/4/lux/bootstrap.min.css',
“材料”:https://bootswatch.com/4/materia/bootstrap.min.css',
“薄荷糖”:https://bootswatch.com/4/minty/bootstrap.min.css',
"脉搏":"https://bootswatch.com/4/pulse/bootstrap.min.css',
“砂岩”:https://bootswatch.com/4/sandstone/bootstrap.min.css',
“单纯形”:https://bootswatch.com/4/simplex/bootstrap.min.css',
"粗略":"https://bootswatch.com/4/sketchy/bootstrap.min.css',
“板岩”:https://bootswatch.com/4/slate/bootstrap.min.css',
“太阳能”:https://bootswatch.com/4/solar/bootstrap.min.css',
“太空实验室”:https://bootswatch.com/4/spacelab/bootstrap.min.css',
“超级英雄”:https://bootswatch.com/4/superhero/bootstrap.min.css',
“联合”:https://bootswatch.com/4/united/bootstrap.min.css',
“雪人”:https://bootswatch.com/4/yeti/bootstrap.min.css',
}
var choice=$(this.text();
if(主题选择){
$('#bootswatch').attr('href',themes[choice])
}
});

还有别的吗 其他一些内容


解决了我的问题。我的问题是在dom完成填充之前加载脚本。

而不是使用href-“#”use href=“javascript:void(0)”。。对于jqueryv3及更高版本和bootstrap3,“#”无效,并引发类似的错误error@NagaSaiA好建议!这使得错误消失,但代码在更改主题时不起作用。有趣的是,我在测试文件中使用了相同的js/css文件,但没有错误,而且可以正常工作console中的新错误是什么?没有新错误@NagaSaiA。它只是没有任何作用。我对测试文件做了与您建议的相同的更改,并且也按预期停止工作。我不认为是这样。正如我提到的,测试文件运行良好。我将所有的脚本源移到头部来测试你的理论,它仍然有效。innerHTML被用作在主题对象中查找值的键。谢谢!虽然这和我的测试代码一样在生产代码中有效,但我无法让它工作。这个错误确实会随着
javascript:void(0)
而消失,但是我在函数条目上放置了一个断点,当我单击一个元素时,我从未到达它。这很可能是因为我的prod导航栏有另一个带有Tagsure的下拉列表!我这里有一个样品。这是我生成的HTML(它是由py脚本生成的,但我一直在通过手动方式对生成的HTML进行更改)将在大约21小时内完成的所有操作的完整版本