在 javaScript或者jQuery中字符串比較沒有equals()方法,要比較兩個字符串是否相等可以直接用==或者is()進行判斷。
一段老的js代碼示例:
var items = document.getElementById("PDStatus").options; if("1"==(<%=checkOut.getFILLER1().substring(10)%>) ){ items[1].selected =true; }else if("2"==(<%=checkOut.getFILLER1().substring(10)%>)){ items[2].selected =true; }else if("3"==(<%=checkOut.getFILLER1().substring(10)%>)){ items[3].selected =true; }else{ items[0].selected =true; }
使用var filler1 = <%=checkOut.getFILLER1()%>;
filler1的類型為obj;如果想要接受的filler為字符串,應該使用如下寫法
var filler1 = "<%=checkOut.getFILLER1()%>";
而非:
var filler1 = <%=checkOut.getFILLER1()%>+"0";