<!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>
<script language="javascript">
function checkLink()
{
var trr = document.getElementsByName("linkTr");
alert(trr.length);
}
window.onload = function()
{
checkLink();
}</script>
</head><body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr name="linkTr">
    <td>&nbsp;</td>
  </tr>
  <tr name="linkTr">
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

解决方案 »

  1.   

    哇, 你肯定说的是IE6吧, 身为一个Web开发程序员, 一定会饱受IE6的折磨的!!
    我一般出现这种错误,直接另外找方法实现了,不然你会很头痛!
      

  2.   

    google查了一下:在IE下只有以下标签支持Name属性
    A, APPLET, BUTTON, FORM, FRAME, IFRAME, IMG, INPUT, OBJECT, MAP, META, PARAM, TEXTAREA ,SELECT
      

  3.   

    用class+jquery可以实现你功能
    <!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>
    <Script src="jquery.js"></script>
    <script language="javascript">
    function checkLink()
    {
        var trr = $(".linkTr");
        alert(trr.length);
    }
    window.onload = function()
    {
        checkLink();
    }</script>
    </head><body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr class="linkTr">
        <td>&nbsp;</td>
      </tr>
      <tr class="linkTr">
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
      

  4.   


    IE下的document.getElementsByName()只能取input元素
    <!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>
    <script language="javascript"> var getElementsByName = function(tag, name){
     var returns = document.getElementsByName(name);
     if(returns.length > 0) return returns;
     returns = new Array(); var e = document.getElementsByTagName(tag);
     for(var i = 0; i < e.length; i++){
    if(e[i].getAttribute("name") == name){
    returns[returns.length] = e[i];
    }
     }
     return returns;
     }
    function checkLink()
    {
        var trr = getElementsByName("tr","linkTr");
        alert(trr.length);
    }
    window.onload = function()
    {
        checkLink();
    }</script>
    </head><body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr name="linkTr">
        <td>&nbsp;</td>
      </tr>
      <tr name="linkTr">
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>