首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

getElementById()方法能不能通过id值获取到<a>标签啊

2012-03-13 
getElementById()方法能不能通过id值获取到a标签啊 - Web 开发 / Ajax我用getElementById()去获取 a

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>

热点排行