jquery 之类的代码在 switch 内不起作用
我的代码是
//global variable
var topMenuSelected = 'Hot';
function switchMenu() {
switch(topMenuSelected){
case 'Hot':
${'#hotMenu'}.css('color', '#fff');
break;
case 'All':
${'#allMenu'}.css('color', '#fff');
break;
default:
break;
}
}
Here hotMenu 和allMenu 是标签 的id。单击这些链接后,我将调用此函数来更改
的颜色。但是 switch 中的
$
字符出现无效字符之类的错误
My code is
//global variable
var topMenuSelected = 'Hot';
function switchMenu() {
switch(topMenuSelected){
case 'Hot':
${'#hotMenu'}.css('color', '#fff');
break;
case 'All':
${'#allMenu'}.css('color', '#fff');
break;
default:
break;
}
}
Here hotMenu and allMenu are ids of a tag <a>
. On click of these links I am calling this function to change the color of <a>
. But the error like invalid character is coming for $
character in switch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些事情
首先将
${'#hotMenu'}
更改为$('#hotMenu')
还要确保您首先加载 jQuery,这也是一个好主意将您的 intiliazing 代码包装在其中
A few things
First change
${'#hotMenu'}
to$('#hotMenu')
Also make sure you are loading jQuery first, and its also a good idea to wrap your intiliazing code within
这需要使用“(”而不是“{”
This needs to use "(" rather than "{"