hr10230322
何-小鱼
2017-04-09 02:56
采纳率: 80%
浏览 1.7k
已采纳

javascript中为什么getElementsByTagName返回数组长度为0?

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>Document</title>
    <script type="text/javascript" src="javascript/display_abbr.js"></script>
    </head>
    <body>
        <h1>What is the Document Object Model?</h1>
        <p>The <abbr title="World Wide Web Consortium">W3C</abbr> defines the <abbr title="Document Object Model">DOM</abbr> as:</p>
        <blockquote cite="http://www.w3.org/DOM/">
            <p>A platform- and language-neutral interface that will allow programs and script to dynamiclly access and update the content,structure and style of documents.</p>
        </blockquote>
        <p>It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate <abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="eXtensible Markup Language">XML</abbr> documents.</p>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • showbo
    已采纳

    你是直接执行displayAbbreviations函数将返回值作为onload事件处理函数,你放dom上面肯定获取不到了

     window.onload = displayAbbreviations//////////();
    
    点赞 评论
  • hr10230322
    何-小鱼 2017-04-09 03:10

    display_arr.js中
    window.onload = displayAbbreviations();
    function displayAbbreviations(){
    if(!document.getElementsByTagName) return false;
    var abbr_arr = document.getElementsByTagName("abbr");
    alert(abbr_arr.length);
    if(abbr_arr.length<1) return false;
    ...
    }

    点赞 评论
  • hr10230322
    何-小鱼 2017-04-09 03:21

    显示有问题呐。。怎么搞的 看不到全部

    点赞 评论

相关推荐