我把鼠标移到超链接上,除了显示本身title的内容外,应该还要显示hello,world!啊,怎么没有hello,world!呢?<!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>
    <title>无标题页</title>
    <script type="text/javascript">
        function initEvent(){
            var links = document.getElementById("a");
            for(var i=0;i<links.length; i++){
                var link = links[i];
                link.onmouseover = mouseOver;
            }
        }
        function mouseOver(){
           var divMain = document.createElement("div");
           divMain.style.position = "absolute";
           divMain.style.top = window.event.clientY;
           divMain.style.left = window.event.clientX;
           divMain.innerText = "hello,world!";
           document.body.appendChild("divMain");
        }
    </script>
</head>
<body onload="initEvent()">
<a href="http://www.tianya.cn" title="最大的华人社区">天涯</a><br /><br />
<a href="http://www.baidu.com" title="竞价排名专用网">百度</a><br /><br />
<a href="http://www.sohu.com" title="搜狐搜狗啥都能搜">搜狐</a><br /><br />
</body>
</html>

解决方案 »

  1.   


    var links = document.getElementById("a");====>var links = document.getElementsByTagName("a");
      

  2.   


        <script type="text/javascript">
            function initEvent() {
                var links = document.getElementsByTagName("a");
                for (var i = 0; i < links.length; i++) {
                    var link = links[i];
                    link.onmouseover = mouseOver;
                }
            }
            function mouseOver() {
                var divMain = document.createElement("div");
                divMain.style.position = "absolute";
                divMain.style.top = window.event.clientY;
                divMain.style.left = window.event.clientX;
                divMain.innerText = "hello,world!";
                document.body.appendChild(divMain);
            }
        </script>
      

  3.   


     document.body.appendChild("divMain");   红色 document.body.appendChild(divMain);  //单引号去掉,,,
      

  4.   

    <!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>
        <title>无标题页</title>
        <script type="text/javascript">
            function initEvent(){
                var links = document.getElementsByTagName("a");
                for(var i=0;i<links.length; i++){
                    var link = links[i];
                    link.onmouseover = mouseOver;
                }
            }
            function mouseOver(){
               var divMain = document.createElement("div");
               divMain.style.position = "absolute";
               divMain.style.top = window.event.clientY;
               divMain.style.left = window.event.clientX;
               divMain.innerText = "hello,world!";
               document.body.appendChild(divMain);
            }
        </script>
    </head>
    <body onload="initEvent()">
    <a href="http://www.tianya.cn" title="最大的华人社区">天涯</a><br /><br />
    <a href="http://www.baidu.com" title="竞价排名专用网">百度</a><br /><br />
    <a href="http://www.sohu.com" title="搜狐搜狗啥都能搜">搜狐</a><br /><br />
    </body>
    </html>
      

  5.   

    document.getElementByTagName(),,,<a> 是个tag