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

JS循环添加事件
    对于JS循环添加事件,就和网上遇到情况一样,输出的值一直都是那个循环的最大i值。如何添加循环事件呢?我也是在无意中突然想到的,以下代码供大家参考,希望对你们的编程有帮助。
for(var t = 0;t < isCheckName.length;t++){
                    Goodsid[t] = document.getElementById("Goodsid"+t);
                    Goods_id[t] = document.getElementById("Goods_id"+t);
                    Goods_name[t] = document.getElementById("Goods_name"+t);
                    provider[t] = document.getElementById("provider"+t);
                    Produce_place[t] = document.getElementById("Produce_place"+t);
                    Size[t] = document.getElementById("Size"+t);
                    Package[t] = document.getElementById("Package"+t);
                    Product_code[t] = document.getElementById("Product_code"+t);
                    Promit_code[t] = document.getElementById("Promit_code"+t);
                    Description[t] = document.getElementById("Description"+t);
                    Price[t] = document.getElementById("Price"+t);
                    Available[t] = document.getElementById("Available"+t);
                    isCheck[t] = document.getElementById("isCheck"+t);
                }
var importGoodsListTr = new Array();//插入行

                alert(new Date());

                  for( var n = 0;n<isCheck.length;n++){
                     isCheck[n].value=n;
                       isCheck[n].onclick=function(){
                         var i =  this.value;
                         if(isCheck[i].checked == true){
                             importGoodsListTr[i]= importGoodsList.insertRow(importGoodsList.rowIndex+1);

                            var importGoo