Code
addEventListener对应IE,attachEvent对应Firefox..
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function test()
{
var element=window.document.forms[0].btn;
if (element.addEventListener)
{
alert("I love you !");
element.addEventListener("click",ck,false);
}else if(element.attachEvent)
{
alert("You are my sunshine!");
element.attachEvent("onclick",ck,false);
}
}
function ck()
{
alert("I love you more than I can sy !");
}
</script>
</head>
<body onload="test()">
<form action="" method="post" name="frm1">
<input type="button" value="Click" name="btn"/>
</form>
</body>
</html>