<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>
Question:
If I changed :
var event = evt || window.event;
var target = event.target || event.srcElement;
to
var event = evt;
var target = event.target;
It still works in IE(I am using IE 10), Does this mean: IE10 also support event.target
, and in the future I do not need to use this kind of code: var target = event.target || event.srcElement;
var target = event.target || event.srcElement;
?
event.target
is already available in IE9+. If you need to support IE6-8, then event.srcElement
needs to be used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.