2010-04-15 64 views
0

你能告訴我什麼是錯這個ASP腳本:爲什麼這個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

我加了 - 您的文章,以便它可以正確格式化。顯然SO有一個列表和代碼塊的錯誤 – Earlz 2010-04-15 15:13:12

+0

javascript/vbscript? 如果它是JavaScript - 我會說:如果( == )將是你的問題 – riffnl 2010-04-15 15:15:21

+0

你也應該指定腳本的類型。 – R0MANARMY 2010-04-15 15:17:45

回答

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 
+4

如果這個錯誤發生了很多,你可能會考慮把它寫成「倒退」,這樣你會得到像這樣的解析錯誤:if(「flash1」= flash)'不能編譯 – Earlz 2010-04-15 15:15:52

+0

@Earlz:這對我來說沒有意義,因爲如果我能記得這樣做,我可以記住使用'=='。 /:] – RedFilter 2010-04-15 15:52:09

+0

男人,我個人不這樣做,正是因爲這個原因。儘管如此,如果你剛剛開始編程以使其成爲一種習慣,那將更加方便 – Earlz 2010-04-15 16:19:37