Javascript如何比较两个字符串

ak2*_*274 2 javascript ajax

这是Javascript函数.请解释如何在Javascript中比较两个字符串.

   <head>
    <script type="text/javascript">
/*javascript function*/ 
    function ajax(str)
    {
    if (str.length==0)
      {
      document.getElementById("res").innerHTML="";    
      return;
      }
      if(str=="Select City")
      {
      alert("Please Select a City");
      }
    document.getElementById("res").innerHTML=="";
    var url="code1.php?q="+str+"&r"+Math.random();
    var obj;
    try{
    obj=new ActiveXObject(Microsoft.XMLHTTP);
    }
    catch(e)
    {
        try
        {
        obj=new XMLHttpRequest();
        }
        catch(e)
        {
        alert("Your browser not suport ajax");
        }
    }
    obj.open('Get',url,true);
    obj.send(null);
    obj.onreadystatechange=function()
    {
    if(obj.readyState==4)
    {
    document.getElementById("res").innerHTML=obj.responseText;
    }
    }
    }
    </script>
    </head>

    <body>

    <select onchange="ajax(this.value)" name="sel" id="btn"><option>Dharmashala</option><option>Manali</option><option>Shimla</option></select>
    <div id="res"></div>
    </body>
    </html>
Run Code Online (Sandbox Code Playgroud)

但它没有用,请建议我这样做的正确方法.

小智 5

=== 用于字符串比较

if(str === "Select City") {
    alert("Please Select a City");`
}
Run Code Online (Sandbox Code Playgroud)