在Firefox 36中,此文档似乎未正确显示。应将标记的值记录到控制台。适用于Chrome。
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
a {
height: 10px;
width: 10px;
margin: 2px;
padding: 2px;
background: mediumaquamarine;
display: block;
}
</style>
</head>
<body>
<a href="#" class="tab">1</a>
<a href="#" class="tab">2</a>
<a href="#" class="tab">3</a>
<a href="#" class="tab">4</a>
<a href="#" class="tab">5</a>
<script type="text/javascript">
var tabs = document.querySelectorAll('.tab');
for(var i = 0; i < tabs.length; i++) {
addTabEv(tabs[i]);
}
function addTabEv(el) {
el.addEventListener('focus', logHTML);
};
function logHTML(e) {
console.log(e.target.innerHTML);
};
</script>
</body>
</html>