0

I'm getting a frustrating javascript error in IE7 that I can't get around. It is working fine in Chrome and Firefox, but not in IE..

The line I am getting the error in is: item = listGetAt(list,'1','-');

This is calling the following custom method:

function listGetAt(list,position,delimiter) {   
if(delimiter == null) { delimiter = '-'; }
list = list.split(delimiter);
if(list.length > position) {
    return list[position];
} else {
    return list.length;
}
}

Can anyone see something I can't?

Many thanks in advance for any help.

Jason

4

1 回答 1

0

糟糕的代码

为什么将字符串作为数字参数传递?

我会考虑

function listGetAt(list,position,delimiter) {   
  delimiter = delimiter || '-';
  if (list.indexOf(delimiter) ==-1) return -1;
  list = list.split(delimiter);
  return list.length>=position?list[position]:null;
}
于 2012-07-24T08:17:27.040 回答