日期:2014-05-16  浏览次数:20381 次

indexOf查找字符串的问题
<script language="javascript">
function changeselect(locationid)
{
var tt=','+@+',';
var ttt=','+locationid+',';
alert(tt.indexOf(ttt));
}
</script>

@是程序从数据库取出的值,类似:1,2,3,4,5这样,拼接成,1,2,3,4,5,这样的字符串,输出过,没问题
locationid是下拉传递上来的整数,拼接成,1,这样的字符串,输出过,也没问题

但是indexOf的值总是为-1


是怎么回事呢?

------解决方案--------------------
var str='1,2,3,5,';
var locationid='3';
alert(str.indexOf(locationid));