提取行间事件,就是将input标签里的onclick事件写到script脚本里
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<input type="button" value="变红" id="btn1"/>
<script>
//代码按顺序从上到下执行,oBtn.onclick脚本需要写在<input>标签下面
var oBtn=document.getElementById('btn1');
function abc(){alert('a');
}
oBtn.οnclick=abc;
//变量和函数名都不加引号,只有作为值的字符串才加
//在JS中,函数进行赋值时,只写函数名,不写小括号
//在html中<input type="button" οnclick="abc()"/>
</script>
<!--这段脚本语言也可以这样写
<script>
var oBtn=document.getElementById('btn1');
oBtn.οnclick=
function (){alert('a');
};
//匿名函数直接赋值,其实在JS里面大部分函数是没有名字的
</script>
-->
</body>
</html>