document是javascript中封装的一个对象,在他中封装了很多有用的方法。你的write是其中一个。当点击body区域时,响应js函数向浏览器输出al对象内容。所以表格中的数据不再显示。。

解决方案 »

  1.   

    write方法被执行,将会向页面重新提交数据。
      

  2.   

    document.write(a1);
    这个应该放在页面加载时执行
    否则会生成新的文档  以前的都没了
      

  3.   

    <td><a href="#">
       //here
       <script src=javascript:scriptdojs()></script>
    </a></td><td>test message2</td>
      

  4.   

    <script src="javascript:dojs()"> </script> 
      

  5.   

    onclick事件要有触发者(事件原),body onload=dojs()
    //会在页面载入完成时,自动触发的
      

  6.   

    晕,本来想在下班前结贴的,结果破网半天都打不开页面
    先谢谢各位了,想问下有没有别的方法输出a1的值,同时不影响后面的table内容明早结贴,再次感谢
      

  7.   

    xiaofanku
    我按照你的试了下,放在了a标签里面,可是还是不显示table的东西~~
    hoho
      

  8.   

    当你调用document.write后你的那段程序就不存在了
    相当与重写当前页面了
      

  9.   

    document.write是页面输出!
    不知你想把函数中的内容输出到哪呀?
    是在页面载入时,显示一个提示?还是某个块中输出! <a>中用的函数中是不能代document.write语句的,//噢我好像明白你要干什么了>?<html>
    <head>
    <title>111</title>
    </head>
    <body onclick="return dojs();">
    <script language="javascript">
        function dojs() 
        {
        var a1=123;
        document.write(a1);
        return true;
        }
    </script><br><table>
    <tr>
    <td><a href="#">xxx</a></td><td>test message2</td>
    </tr>
    </table></body>
    </html>
    你试一试,我现在网吧没法试!我回家在我笔记本上试一试,我明天上完课,晚上再给你回复消息
      

  10.   

    。document就是整个页面的对象
    你加载之后再次write会覆盖掉原来的页面内容(含table的内容)
    如果要追加内容  不能适用document.write来追加。
    请用appendChild或者innerHTML innerText 这些来操作
      

  11.   

    document.write()会覆盖整个页面的内容,如果不想覆盖的话,试试document.open();
    document.write();
    document.close();
      

  12.   


    function mohu(){
    document.open();
    document.write("sdfsdf");
    document.write("ssssssssssssssssss");
    document.close();
    }调用此方法后页面输出:"sdfsdfssssssssssssssssss"
      

  13.   

    饿,我又发现个问题,写在函数里的write就会重写页面,而单独的一句write就不会,这是bug么?还是就是这么设计的<html>
    <body onclick="dojs();">
    <script language="javascript">    
        function dojs() 
        {
        var a1="1234";
    //    document.open(); 
        document.write(a1); 
    //    document.close(); 
        }
    </script>
    <br>
    <script language="javascript">onload=document.write("^__^");</script>
    <table>
    <tr>
    <td><a href="#">xxx</a></td><td>test message2</td>
    </tr>
    </table>
    </body>
    </html>
      

  14.   

    页面渲染完之后会执行document.close();这时再执行document.write会重新执行document.open();所有的文档内容就被冲没了。
      

  15.   

    楼主问的这个问题在《javascript权威指南》中作者专门讲过:Be aware, however, that you can use the write() method to output HTML to the current document only while that document is being parsed. That is, you can call document.write() from within top-level code in <script> tags only because these scripts are executed as part of the document parsing process. If you place a document.write() call within a function definition and then call that function from an event handler, it will not work as you expectin fact, it will erase the current document and the scripts it contains! 
      

  16.   

    <script language="javascript">onload=document.write("^__^");</script>这个是与页面同级的,不是你点击触发的