日期:2014-05-16  浏览次数:20791 次

getElementById()方法能不能通过id值获取到<a>标签啊 - Web 开发 / Ajax
我用getElementById()去获取 <a> 标签一直出错,错误提示“缺少标识符”,怎么回事啊,不能吗?

------解决方案--------------------
<!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>
<script type=text/javascript>
function goToIndex()
{
var obj = document.getElementById( "index ");
obj.setAttribute( "class ", "nav_index_active ");
obj.setAttribute( "className ", "nav_index_active ");
}
</script>
<style>
.nav_index
{
color:#CC0000;
}
.nav_index_active
{
font-size:38px;
}
</style>
</head>
<body>
<div id= "header ">
<ul>
<li> <a id= "index " href= "# " onclick= "goToIndex() " class= "nav_index "> test </a> </li>
</ul>
</div>
</body>
</html>