js事件

1.内联模式

//在HTML 中把事件处理函数作为属性执行JS 代码
<input type="button" value="按钮" onclick="alert('Lee');" /> //注意单双引号
//在HTML 中把事件处理函数作为属性执行JS 函数
<input type="button" value="按钮" onclick="box();" /> //执行JS 的函数 PS:函数box不得放到window.onload 里面,这样就看不见了。

2.脚本模式

var input = document.getElementsByTagName('input')[0]; //得到input 对象
input.onclick = function () { //匿名函数执行 ,onclick的c没有大写
  alert('Lee');
};
原文地址:https://www.cnblogs.com/luhailin/p/6610747.html