js中判斷字符串相等使用==


在 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";


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM