日期:2014-05-16 浏览次数:20390 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> .nav{ width:510px; overflow:hidden; background:red; } .nav a{ width:100px; height:40px; line-height:40px; text-align:center; background-color:#0C0; border:1px solid #fff; float:left; } .nav .clickname{ background:#000;} </style> <script> window.onload = function(){ var nav = document.getElementById("nav"); var list = nav.getElementsByTagName("a"); for(var i=0; i < list.length; i++ ){ list[i].onclick = (function(n){ return function(){ //alert(list[n]); list[n].className = "clickname"; } })(i); } } </script> </head> <body> <div class="nav" id="nav"> <a href="javascript:void(0);">首页</a> <a href="javascript:void(0);">友情链接</a> <a href="javascript:void(0);">关于我们</a> <a href="javascript:void(0);">诚聘英才</a> <a href="javascript:void(0);">网站地图</a> </div>