IE 10是否支持event.target?

时间:2013-06-29 06:18:18

标签: javascript

<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;

1 个答案:

答案 0 :(得分:4)

event.target已在IE9 +中提供。如果您需要支持IE6-8,则需要使用event.srcElement