<script>
 var a=getElementById('a');
 b=createElement("input");
 a.type="button";
 a.oncilck="??"//a()参数是变量
</script>
在createElement里创建一个button按钮,怎么给他添加onclick事件,js方法已有,而且有参数,参数是个变量

解决方案 »

  1.   

    就是你这样的啊!onclick有个拼写错误。oncilck->onclick
      

  2.   

    在网上找到的都是b.onclick=a(){};这样的 而对已有方法a()没有看到 直接用b.onclick=a(i);是不执行的
      

  3.   

    b.onclick=a(i){
    alert(i);
    }
    这样执行么?
      

  4.   

    b.onclick=function a(i){
    alert(i);
      

  5.   


    function a(str){
    alert(str);
    }var a=getElementById('a');
    b=createElement("input");
    b.type="button";
    b.onclick=a(i);
      

  6.   

    加参数后传进的参数是个数字 alert出的是object MouseEvent 
      

  7.   

    而且这么写没参数的时候 b.onclick=a;是好用的b.onclick=a();就不行了,参数也就加不上了
      

  8.   


    <script> 
    function a(obj){
      alert(obj.value)
    }
    window.onload=function(){
      var b = document.createElement("input"); 
      b.type="button";
      b.value="click" 
      b.onclick = (function(n){ return function(){a(n);} })(b);
      document.body.appendChild(b);
    }
    </script> 
      

  9.   

    b.onclick=function a(i){ 
    alert(i); 
      

  10.   

    person.onclick=(function (n){return function(){bb(json['faxnameary'][num]);}})(person); 传进一个数组alert后就是undefined
      

  11.   

    person.onclick=(function (n){return function(){bb('程序员');}})(person);
      

  12.   

    我要调用的是用js创建的<input>的id值,我现在在页面上取不到,直接用js赋值的话总等于for循环最后一个值