html 动态修改onclick事件

来源:互联网 发布:淘宝装修素材网站 编辑:程序博客网 时间:2024/05/19 13:58

1 每次点击,执行函数不同

<body><input type="button" id="zhch" value="我的注册函数是hello" onclick="hello()"/><script type="text/javascript">function hello(){alert("hello");document.getElementById("zhch").value = "我的注册函数是word";document.getElementById("zhch").onclick = word;}function word(){alert("word");}</script></body>

 

2 第一次点击执行方法1,第二次点击执行方法1和方法2,第三次点击执行方法1、方法2和方法3等等

<body><input type="button" id="zhch" value="我的注册函数是hello" onclick="hello()"/><script type="text/javascript">function hello(){alert("hello");document.getElementById("zhch").addEventListener("click",word,false); }function word(){alert("word");}</script></body>

 

原创粉丝点击