J
John Smith
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Item one</a></li>
<li><a href="#">Item two</a></li>
<li><a href="#">Item three</a></li>
<li><a href="#">Item four</a></li>
<li><a href="#">Item five</a></li>
</ul>
</div>
<script defer="false" type="text/javascript">
function initNavlists(){
var nav = document.getElementById('navlist');
if (nav){
var links = nav.getElementsByTagName('a');
for (var i=0;i<links.length;i++)
{
var str = links.innerHTML;
//alert(str);
links.onclick = function(){ alert(str); };
}
}
}
initNavlists();
</script>
</body>
</html>
Why i always get the last item in the alert box?
How to get the rest?
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="#" id="current">Item one</a></li>
<li><a href="#">Item two</a></li>
<li><a href="#">Item three</a></li>
<li><a href="#">Item four</a></li>
<li><a href="#">Item five</a></li>
</ul>
</div>
<script defer="false" type="text/javascript">
function initNavlists(){
var nav = document.getElementById('navlist');
if (nav){
var links = nav.getElementsByTagName('a');
for (var i=0;i<links.length;i++)
{
var str = links.innerHTML;
//alert(str);
links.onclick = function(){ alert(str); };
}
}
}
initNavlists();
</script>
</body>
</html>
Why i always get the last item in the alert box?
How to get the rest?