This article mainly shares with you the detailed explanation of JS registration event examples, hoping to help everyone.
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> //要操作页面的元素(标签)那就要写到onload中, //不操作可以不用 function f1() { alert('迁徙猿有很多猿'); } onload = function () { //在html中注册事件加(),在这写不加 document.getElementById('btn').onclick = f1; 注册事件 }; </script></head><body> <input type="button" name="name" value="神奇的按钮" id="btn" /> <!-- onclick="f1();"-->执行代码</body></html>
Related recommendations:
Common methods about js registration events_javascript skills
The above is the detailed content of Detailed explanation of JS registration event examples. For more information, please follow other related articles on the PHP Chinese website!