table1 = document.getElementById("MYtable");
var count = 0;
for(var i=0,l=table.rows.length;i<l;i++)
{
if(/^\s*&/.test(table.rows[i].firstChild.innerHTML.replace("&nbsp;","")))
{
count++;
}
}
alert(count);

解决方案 »

  1.   

    谢谢楼上,提示找不到对像
    <table id="mytable">
    <tr>
    <td>1</TD>
    <td>明天会更好</TD>
    <TR>
    <tr>
    <td>2</TD>
    <td>明天会更好</TD>
    <TR>
    <tr>
    <td></TD>
    <td>好好好</TD>
    <TR>
    </TABLE>
    <script>
    function Yes(){
    table1 = document.getElementById("MYtable");
    var count = 0;
    for(var i=0,l=table.rows.length;i<l;i++)
    {
    if(/^\s*&/.test(table.rows[i].firstChild.innerHTML.replace("","")))
    {
    count++;
    }
    }
    }
    alert(count);
    </script>
    <input type="button" id="btn_no" onclick="yes()" value="yes" />
      

  2.   

    <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type"content="text/html; charset=gb2312"/>
    <title>无标题文档</title>
    </head><body><table id="mytable">
    <tr>
    <td> 1 </TD>
    <td> 明天会更好 </TD>
    </tr>
    <tr>
    <td> 2 </TD>
    <td> 明天会更好 </TD>
    </tr>
    <tr>
    <td> </TD>
    <td> 好好好 </TD>
    </tr>
    </TABLE>
    <input type="button" id="btn_no" onclick="alert(tableCount());" value="yes" />
    </body>
    </html>
    <script>
    function tableCount(){
    table1 = document.getElementById("mytable");
    var count = 0;
    for(var i=0,l=table1.rows.length;i<l;i++)
    {
    if(!/^\s*$/.test(table1.rows[i].cells[0].innerHTML.replace("&nbsp","")))
    {
    count++;
    }
    }
    return count;
    }
    alert(tableCount());
    </script>
      

  3.   

    非常谢谢楼上的大哥.但我的第一列有一个checkbox,一个文本框,这句
    if(!/^\s*$/.test(table1.rows[i].cells[0].innerHTML.replace("&nbsp","")))
    应该怎样写?
      

  4.   

    我的意思是当第一列中文本框中的值为空时,
    if(!/^\s*$/.test(table1.rows(i).cells(0).getElementsByTagName("input")[1].value.replace("&nbsp","")))
    这样写为什么不正确?
      

  5.   

    if(!/^\s*$/.test(table1.rows(i).cells(0).getElementsByTagName("input")[0].value)))