Why is this ASP Script not working?
Could you tell me whats wrong with this ASP script:
I think the error is in the if
statement
<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>开发者_运维问答;
Replace
if (flash = "flash1")
with
if (flash == "flash1")
etc.
A single =
is for assignment, not for testing equality. JSLint is a great tool for picking up these kinds of errors:
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
精彩评论