<body>
<script>
var btn=document.createElement("input");
btn.type="button";
btn.value="test"
btn.attachEvent("onclick",a)
document.body.appendChild(btn)
function a(){
alert(event.srcElement.value)
}
</script>
</body>

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1984/1984146.xml?temp=.2448999
      

  2.   

    <body>
    <script>
    var btn=document.createElement("input");
    btn.type="button";
    btn.value="test"
    btn.attachEvent("onclick",a)
    document.body.appendChild(btn)
    function a(){
    alert(event.srcElement.value)
    }
    </script>
    </body>
      

  3.   

    <html>
    <body>
    <script>
    var btn=document.createElement("input");
    btn.type="button";
    document.body.insertAdjacentElement("afterBegin",btn);
    btn["onclick"] = function() {alert("you have press me")}
    </script>
    </body>
    </html>