码迷,mamicode.com
首页 > Web开发 > 详细

js事件

时间:2017-03-24 14:07:34      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:log   size   双引号   执行   images   tag   element   nbsp   技术分享   

技术分享

技术分享

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‘);
};

 

js事件

标签:log   size   双引号   执行   images   tag   element   nbsp   技术分享   

原文地址:http://www.cnblogs.com/luhailin/p/6610747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!