当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Unexpected token ( error

问题描述:

hello can anyone help me debug little error that my eyes seem to be skipping. error is: unexpected ( error. Are my array syntex correct?

function SourceClusting()

{

// grabbing count

var table = document.getElementById('OSDataCount');

var counter= table.rows[1].children[0].innerHTML

// putting all variable into arrays

var latitude()

var longitude()

var i

var marker =[];

// placing values into arrays

for (i=1;i == counter;i++)

{

longitude[i]=table.rows[i].children[6].innerHTML;

latitude[i]=table.rows[i].children[5].innerHTML;

marker[i]=new GMarker(new GLatLng(longitude[i],latitude[i]));

}

var markerCluster = new MarkerClusterer(map, marker);

}

cheers

网友答案:

Quite a few things:

  • You have to parseInt() the string you get from var counter = ..., as a string can't be used in comparisons with integers the way you'd like.
  • var latitude = () should be var latitude = [], as it's an array, Don't forget those semicolons!
  • You usually use a lesser-than sign in a loop, not an equality sign ==.
  • You can condense the loop by initializing i within it.

Try this new, possibly working code:

function SourceClusting() {
    // grabbing count
    var table = document.getElementById('OSDataCount');
    var counter= parseInt(table.rows[1].children[0].innerHTML, 10);
    // putting all variable into arrays
    var latitude = [];
    var longitude = [];

    var marker =[];

    // placing values into arrays
    for (var i = 0; i < counter; i++)
        {
        longitude[i]=table.rows[i].children[6].innerHTML;
        latitude[i]=table.rows[i].children[5].innerHTML;

        marker[i]=new GMarker(new GLatLng(longitude[i],latitude[i])); 

        }

    var markerCluster = new MarkerClusterer(map, marker);


}
网友答案:

The problems are in these lines:

var latitude()
var longitude()

You mean

var latitude;
var longitude;

or possibly

var latitude = [];
var longitude = [];

since you seem to be treating them as arrays.

网友答案:

var latitude() is nonsense. I suspect you mean var latitude = [];

(With a similar correction for the following line)

网友答案:

If you're trying to instantiate an array, instead of:

var latitude();

it should be:

var latitude = [];
网友答案:

You declare var latitidue(), but that doesn't make anysense. Hence the unexpected '('. Also, missing semi-colon after statement.

分享给朋友:
您可能感兴趣的文章:
随机阅读: