if语句在我的for循环中不起作用

时间:2013-01-16 05:04:06

标签: javascript

目前我正在开发Java脚本项目。该项目用于检查从UDDF文件中选择的值以及UDDF文件中的全部值。但是用于比较的if语句不起作用。我已将我的代码放在下面

function parseUddf(){
var myArray=new Array("null","airportID","airportSiteNo","faaRgn","uddfVer","null","airportName","verificationDate",
"city","state","horizontalelevationdatum","horiAccuracy","elevAccuracy","orthoDatum","orthoAccuracy",
"magDec","verificationDate","airportOrthoElev","airportEllipsoidElev","airportElevationLoc",
"verificationDate","towerFloorOrthoElev","towerFloorEllipElev","verificationDate","arpLatitude","arpLongitude");
var selt=document.getElementById("textdis").value;
var x = document.getElementById("uddf").value;
x = x.split("@");
var x0 = x[0];
x0 = x0.split("|");
var j=x0.length;
alert(j);
for(var i=1;i<x0.length;i++){
        alert("selt="+selt.toString());
    if(selt.toString()==x0[i])
 {
          alert("success");
          alert("i="+i);
          alert(myArray[i]);
//document.getElementById("textdistitleid").value=myArray[i];
 break;
    }


    }
}

UDDF文件值为:

| FAI | 50219.A | AAL | 1.07 | | FAIRBANKS INTERNATIONAL AIRPORT | 1592011 | | FAIRBANKS | ALASKA | | NAD83 | 5 CM | 15 CM | NAVD88 | 25 CM | | -20.4 | 1592011 | | 439.0 | 470.0 | 20R + 3990 | 1592011 | | 529.0 | | | | 644854.4 | -1475123.2 |

我需要你的帮助

1 个答案:

答案 0 :(得分:0)

您可以使用.equals():

,而不是使用==
selt.toString().trim().equals(x0[i].trim())

您可以从here

获取javascript的trim()函数