你能告诉我这个ASP脚本有什么问题:
我认为错误发生在if
声明
<script>
productID=new Array()
variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")
if(variaveis!=""){
for(i=0;i<variaveis.length;i++){
nvar=variaveis[i].split("=")
productID[nvar[0]]=unescape(nvar[1])
}
}
function QueryString(variavel){
return productID[variavel]
}
document.writeln (QueryString("c"));
var flash = (QueryString("c"));
if (flash = "flash1")
{
document.write("<b>flash1</b>");
}
else if (flash = "flash2")
{
document.write("<b>flash2</b>");
}
else
{
document.write("<b>another</b>");
}
</script>
答案 0 :(得分:5)
替换
if (flash = "flash1")
与
if (flash == "flash1")
等
单个=
用于分配,而不是用于测试相等性。 JSLint是一个很好的工具,可以解决这些错误:
Error:
Problem at line 1 character 20: Use the array literal notation [].
productID=new Array()
Problem at line 1 character 22: Missing semicolon.
productID=new Array()
Problem at line 2 character 77: Missing semicolon.
variaveis=location.search.replace(/\x3F/,"").replace(/\x2B/g," ").split("&")
Problem at line 5 character 33: Missing semicolon.
nvar=variaveis[i].split("=")
Problem at line 6 character 41: Missing semicolon.
productID[nvar[0]]=unescape(nvar[1])
Problem at line 11 character 29: Missing semicolon.
return productID[variavel]
Problem at line 16 character 11: Expected a conditional expression and instead saw an assignment.
if (flash = "flash1")
Problem at line 20 character 16: Expected a conditional expression and instead saw an assignment.
else if (flash = "flash2")
Implied global: productID 1,6,11, variaveis 2,3,4,5, i 4,5, nvar 5,6, unescape 6