var channels;
var che = document.getElementsByName("channles");
for(var i = 0 ; i < che.length ; i++){
if(che[i].checked){
channels += che[i].value+",";
}
}
channels = channels.substring(0,channels.length-1);
alert("channels");这个输出的时候 选中的值也输出来了 但是在前面后多个undefined
输出结果:undefined4,5,6
为什么会多出个undefined 这个
这样声明试试!!!
你这样alert他弹出的应该是"channels"吧~~~!!!
声明channels的时候没有给初值、默认值就是undefined、
一般这样声明是为了方便、但是你用它来做运算就不能图这个方便了!
一般情况var v;
v = "神马" ;这样就将undefined覆盖了!
但是你这种运算很明显是覆盖不了的!
var channels='';