<html>
<body>
<html>
<body>
<ul id="navigation">
<li><a href="Code libraries">Code libraries</a></li>
<li><a href="Web sites">Web sites</a></li>
<li><a href="Archives">Archives</a></li>
</ul>
</body>
</html>
</body>
</html>
<script>
window.onload = function () {
var navigation = document.getElementById("navigation");
navigation.onclick = function (evt) {
var event = evt || window.event;
var target = event.target || event.srcElement;
var text = "Link's text: " + target.innerHTML;
alert(text);
}
};
</script>
问题:
如果我改变了:
var event = evt || window.event;
var target = event.target || event.srcElement;
至
var event = evt;
var target = event.target;
它仍然可以在 IE 中使用(我使用的是 IE 10),这是否意味着:IE10 也支持event.target
,并且将来我不需要使用这种代码:var target = event.target || event.srcElement;
?