2009-10-11 55 views
0

如何檢查javascript中的值。例如:檢查javascript中的值

document.formname.subcategory.options[0]=new Option("Select Sub-Category",""); 
document.formname.subcategory.options[1]=new Option("Colleges","Colleges"); 
document.formname.subcategory.options[2]=new Option("Institutes","Institutes"); 
document.formname.subcategory.options[3]=new Option("Schools","Schools"); 
document.formname.subcategory.options[4]=new Option("Tuitions","Tuitions"); 
document.formname.subcategory.options[5]=new Option("Universities","Universities"); 

我該如何檢查它的值是「Colleges」還是「Schools」等?這是這樣嗎?

document.formname.subcategory.options.value == "Universities" 

還是這樣?

document.formname.subcategory.options.value == 5 

回答

0

第一招:

document.formname.subcategory.options.value == "Universities"; 

值是表單提交時將被髮送到服務器,所以你比較字符串的字符串的字符串。 :D