js事件绑定的几种方法

来源:互联网 发布:linux搭建jenkins环境 编辑:程序博客网 时间:2024/05/21 21:35

1、在html的元素中直接写:

   例:

       

  <script>                   function method(){                            alert('pioneer!');                   }        </script>       HTML:         <input onclick="method()"/>

2、直接在js中绑定

     

<script>          documment.getElementByID('txtNumber').onclick=method;          function method(){                  alert('pioneer');         }          </script>   HMTL:    <input id="txtNumber" />


3、只支持IE的attachEvent方法;

  

document.getElementByID('').attachEvent('onclick',method);


0 0
原创粉丝点击