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";
原文地址:https://www.cnblogs.com/DiZhang/p/12544892.html