【发布时间】:2018-08-16 22:05:42
【问题描述】:
所以我正在尝试使用这个简单的代码:
$(`#${id}`).css({
`position`: `fixed`
}).width(width).height(height);
但是,中间行在执行时给我一个错误:Uncaught SyntaxError: Unexpected template string。我不确定我还能在为什么会发生的问题上添加什么,所以我会让你们知道的。
【问题讨论】:
-
你能显示堆栈跟踪吗? (发生错误的行号)。另外,尝试将
`position`替换为"position",将`fixed`替换为"fixed" -
无法复制错误jsfiddle,能否提供
id的值。 -
@finw3 那是因为您将两个字符串参数传递给
css(...)而不是一个对象。 jsfiddle.net/6nu4evx8/9
标签: javascript jquery templates syntax