执行 init() 后,页面中不再存在sde()!
使用“ document.write”后页面内容被重写了

解决方案 »

  1.   

    你重写的页面中已经不包含那个JAVASCRIPT函数了
    按照你的思路需要再写一遍
      

  2.   

    <html>
    <head>
    <script>
    function sde()
    {
      alert("ShowVcardJID");       }function init()
    {
       var str = '<script>function sde(){alert("ShowVcardJID");}</scr'+'ipt><div><A href="javascript:void(0)" onclick="sde();">test!</a></div>';
       document.write(str);    
    }</script>
    </head><body>
    <div><A href="#" onclick="sde();">test!</div>  (此句能执行sde())
    <input type="button" onClick="init();" value="init"/> (动态生成的页面,无法执行sde()函数)

    </body>
    </html>
      

  3.   

    你应该这样
    x.innerHTML = '<div><A href="javascript:void(0)" onclick="parent.sde();">test!</a></div>';
       <div id=x></div>
      

  4.   

    找到了: 
    Document.write( ) is usually used in one of two ways. First, it can be invoked on the current document within a <script> tag or within a function that is executed while the document is being parsed. In this case, the write( ) method writes its HTML output as if that output appeared literally in the file at the location of the code that invoked the method. Second, you can use Document.write( ) to dynamically generate the contents of a document for a window other than the current window. In this case, the target document is never in the process of being parsed, and so the output cannot appear "in place" as it does in the case just described. In order for write( ) to output text into a document, that document must be open. You can open a document by explicitly calling the Document.open( ) method. In most cases this is unnecessary, however, because when write( ) is invoked on a document that is closed, it implicitly opens the document. When a document is opened, any contents that previously appeared in that document are discarded and replaced with a blank document.