js(六)

来源:互联网 发布:电能量数据采集终端 编辑:程序博客网 时间:2024/04/27 20:20

<input type="button" onclick="func1()" value="click">

<input type="button" id="click2" value="click2">
<input type="button" id="click3" value="click3">
<script type="text/javascript">
    function func1(){
        alert('hello');
    }
    //html 和 javascript相分离的时候,给这个元素绑定一个事件
document.getElementById('click2').onclick=function(){
        alert('hehe');
}

//addEventListener()参数1,绑定的事件名(事件名是去掉on的)  参数2,执行的函数名 参数3:没什么作用
document.getElementById('click3').addEventListener('click',func3,false);
document.getElementById('click3').addEventListener('click',func4,false);
function func3(){
    alert('hello');
}
function func4(){
    alert('welcome');
}
原创粉丝点击