[英]JavaScript Error: Unexpected Identifier
I have a script that performce this action:我有一个执行此操作的脚本:
document.getElementById("bildfram2").style.backgroundImage = "url("bilder[count]")";
I have an array looking like this:我有一个看起来像这样的数组:
var bilder = ["../img/startsida/nature1.jpg","../img/startsida/nature2.jpg","../img/startsida/nature3.jpg","../img/startsida/nature4.jpg"];
I get this error from the first line of code:我从第一行代码得到这个错误:
Uncaught SyntaxError: Unexpected identifier
Can someone help me fix the issue!有人可以帮我解决问题吗! Thanks!
谢谢!
You need to concatenate a string and a variable with +
您需要使用
+
连接字符串和变量
document.getElementById("bildfram2").style.backgroundImage =
"url(" + bilder[count] + ")";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.