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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ShelleyLittlehero/article/details/82876986

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

猜你喜欢

转载自blog.csdn.net/ShelleyLittlehero/article/details/82876986