js遍历table,gridview

//遍历table

var tableObj = document.getElementById("tableName");
var str = "";
for(var i=0;i<tableObj.rows.length;i++)
{
   for(varj=0;j<tableObj.rows[i].cells.length;j++)
   {
      //str += tableObj.rows[i].cells[j].innerHTML+"   ";

           for(var z=0;z<tableObj.rows[i].cells[j].children.length;z++)
           {
        var text = tableObj.rows[i].cells[j].children[z];//取得text object
                str += text.value;
           }
   }
   str+="\n";
}
alert(str);

//遍历gridview

function ValidateGridViewScore()
    {
            var gv=document.getElementById("gvGradeInput");
            var array=new Array();
           for( i=1;i<gv.rows.length;i++)
           {
             var score=document.getElementById(gv.rows[i].cells[2].firstChild.id).value;
           //var GridView=document.getElementById("gvGradeInput");
          // for(var i=1;i <GridView.rows.length;i++)
          //{
               //var TextBox=GridView.rows[i].cells[2].getElementsByTagName("input")[0].value;

                if(parseInt(score)>100||parseInt(score)<0)
                {
                    var xm=gv.rows[i].cells[1].innerText;
                    array .push (xm);
                }
            }
            if(array .length >0)
            {
               alert(array+"的成绩必须大于等于0且小于等于100");
                return false ;
            }
            else
            {
                alert("可以录入!");
                return false ;
            }
          
     }
    

posted @ 2009-03-27 21:54  Blue Sky ......  阅读(1194)  评论(0编辑  收藏  举报