时间:2021-07-01 10:21:17 帮助过:2人阅读
<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>相关推荐:
关于js注册事件的常用方法_javascript技巧
以上就是JS注册事件实例详解的详细内容,更多请关注Gxl网其它相关文章!