<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 3.1">
<title>Document Title</title>
</head>
<script language="javascript">
 function rrr(){
var a=document.createElement("INPUT");
    a.setAttribute("type","button");
    a.setAttribute("name","newname");
    a.setAttribute("value","提交");
a.onclick=ttt;
    document.body.appendChild(a);  
    
 }
 function ttt(){
alert("我现在在点击新创建的按钮了!");
 }
</script><body >
<form name="aaa">
 <input type="button" value="show" onclick="rrr()">
</form>
<!-- Insert HTML here -->
</body>
</html>

解决方案 »

  1.   

    function rrr(){
        var a=document.createElement("<INPUT type=button name=newname value=提交>");
        a.onclick = ttt;
     
        document.body.appendChild(a);  
        
     }
     function ttt(){
    alert("我现在在点击新创建的按钮了!");
     }带 name 的对象必须在createElement的时候就把name创建好, 通过a.name是不能赋值的
      

  2.   

    <html>
    <head>
    <meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 3.1">
    <title>Document Title</title>
    </head>
    <script language="javascript">
     function rrr(){
    var a=document.createElement("INPUT");
        a.setAttribute("type","button");
        a.setAttribute("name","newname");
        a.setAttribute("value","提交");
    a.onclick=function(){
    alert("我现在在点击新创建的按钮了!");
    };
        document.body.appendChild(a);  
        
     }
    </script><body >
    <form name="aaa">
     <input type="button" value="show" onclick="rrr()">
    </form>
    <!-- Insert HTML here -->
    </body>
    </html>
      

  3.   

    a.setAttribute("onclick",ttt);// a.setAttribute("onclick","ttt()");