FF和IE获得事件的方法不一样:
IE使用window.event,而FF直接使用参数event,
<html>
<head>
<title>IE和火狐事件</title>
</head>
<script type="text/javascript">
document.onkeydown = function(event)
{
var event = event ? event : window.event;
if (event.keyCode == 13)
{
var btn = document.getElementById("btnLogin");
btn.focus();
btn.onclick();
}
};
</script>
<body>
<input type="button" name="btnLogin" value="登 录" onclick="return Button1_onclick()" tabindex="3" id="btnLogin" class="Button" style="margin-top: 8px" />
<input name="tbUserName" type="text" id="tbUserName" runat="server" />
</body>
</html>
<head>
<title>IE和火狐事件</title>
</head>
<script type="text/javascript">
document.onkeydown = function(event)
{
var event = event ? event : window.event;
if (event.keyCode == 13)
{
var btn = document.getElementById("btnLogin");
btn.focus();
btn.onclick();
}
};
</script>
<body>
<input type="button" name="btnLogin" value="登 录" onclick="return Button1_onclick()" tabindex="3" id="btnLogin" class="Button" style="margin-top: 8px" />
<input name="tbUserName" type="text" id="tbUserName" runat="server" />
</body>
</html>
<!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>
<title>如何获取事件触发源(兼容IE和FireFox)</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
function ClickMe(e)
{
var src = e.target || window.event.srcElement;
alert(src.innerHTML);
}
function ClickMe2()
{
var e = arguments[0] || window.event;
var src = e.srcElement || e.target; // src 就是事件的触发源
alert(src.innerHTML);
}
</script>
</head>
<body>
<button onclick="ClickMe(event)">测试</button>
<button onclick="ClickMe2(event)">测试2</button>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>如何获取事件触发源(兼容IE和FireFox)</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript">
function ClickMe(e)
{
var src = e.target || window.event.srcElement;
alert(src.innerHTML);
}
function ClickMe2()
{
var e = arguments[0] || window.event;
var src = e.srcElement || e.target; // src 就是事件的触发源
alert(src.innerHTML);
}
</script>
</head>
<body>
<button onclick="ClickMe(event)">测试</button>
<button onclick="ClickMe2(event)">测试2</button>
</body>
</html>