h1=document.createElement("a");
a.innerText="go";
h1.setAttribute("href","javascript:myfun()");
ie这样是不行的 为什么 

解决方案 »

  1.   

    感觉是一个逗号,和一个分号书写错误.......
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <HTML><head>
    <style type="text/css"></style></head>
    <BODY><script>
    var h1=document.createElement("a"); 
    h1.innerHTML="go"; 
    h1.setAttribute("href","javascript:myfun()");
    document.body.appendChild(h1)function myfun(){
    alert('a')
    }
    </script>
    </BODY></HTML>
      

  2.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script>
    window.onload = function(){
    h1=document.createElement("A"); 
    h1.innerText="go"; 
    h1.setAttribute("href","javascript:myfun()");
    document.body.appendChild(h1);
    };
    function myfun(){
    alert("myfun");
    }
    </script>
    </head><body></body></html>
      

  3.   

    晕,IE是这么写的:h1.href="javascript:myfun()"
      

  4.   


       hh=document.createElement("a"); 
    hh.innerText="go";
    hh.setAttribute("href", "javascript:myfun()");
    document.body.appendChild(hh);
    function myfun()
    {
    alert("hello");
    }