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

帮我看我的代码 为什么总是NaN
为什么最后alert最后的值是NaN   我也做类型转换了   我是超超级菜鸟   应该得到的是选中框的值的和啊.

<button   onClick= "add() "> add </button>
<button   onClick= "del() "> del </button>
<table   id= "t1 "   border= "1 "> </table>
<script   language= "JavaScript ">
function   add(){
var   tt=t1.insertRow();
tt.insertCell().innerHTML   =   ' <input   type= "checkbox "   name= "tt "> ';
tt.insertCell().innerHTML   =   ' <input   name= "y "   type= "text "   /> ';
}
function   del(){
var   s;
var   t;
var   c   =   document.getElementsByName( 'tt ');
var   b=document.getElementsByName( 'y ')
for(var   i=0;   i <c.length;   i++){
if(c[i].checked)
t=b[i].value;
s+=parseFloat(t);

}
alert(s);
}
</SCRIPT>


------解决方案--------------------
初始化 var s=0;