87,997
社区成员




<div>
<a href="#">网页</a>
<a href="#">新闻</a>
<a href="#">地图</a>
<a href="#">音乐</a>
<a href="#">图片</a>
</div>
<span>
<input type="text" value=""></input>
</span>
<script type="text/javascript">
function selectTag(obj,vv){
document.getElementById("kw").value=vv;
var parentNode=obj.parentNode;
var aList=parentNode.children;
for(var i=0;i<aList.length;i++)
aList[i].style.color='#0000cc';
obj.style.color='#000';
}
</script>
最后一句能这样写吗?obj.className='aaa';
<style>
.b {color:black}
.r {color:red}
</style>
<a href="#" class="b" onclick="this.className='r'">1</a>
<a href="#" class="b" onclick="this.className='r'">2</a>
<a href="#" class="b" onclick="this.className='r'">3</a>
<a href="#" style="color:black" onclick="this.style.color='red'">4</a>
<a href="#" style="color:black" onclick="this.style.color='red'">5</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>
<style>
a{color:#000;}
</style>
<script>
function selectTag(obj,vv){
//假设所有a初始字体颜色为黑色
document.getElementById("kw").value=vv;
var parentNode=obj.parentNode;
var aList=parentNode.children;
for(var i=0;i<aList.length;i++)
aList[i].style.color='#000';
obj.style.color='red';
}
</script>
</head>
<body>
<div>
<a href="javascript:void(0)" onClick="selectTag(this,'网页')">网页</a>
<a href="javascript:void(0)" onClick="selectTag(this,'新闻')">新闻</a>
<a href="javascript:void(0)" onClick="selectTag(this,'地图')">地图</a>
<a href="javascript:void(0)" onClick="selectTag(this,'音乐')">音乐</a>
<a href="javascript:void(0)" onClick="selectTag(this,'图片')">图片</a>
</div>
<span>
<input id="kw" type="text" value="" size="30"></input>
</span>
</body>
</html>
<script type="text/javascript">
function selectTag(vv){
document.getElementById("kw").value=vv;
}
</script>
<div>
<a href="javascript:void(0)" onClick="selectTag('网页')">网页</a>
<a href="javascript:void(0)" onClick="selectTag('新闻')">新闻</a>
<a href="javascript:void(0)" onClick="selectTag('地图')">地图</a>
<a href="javascript:void(0)" onClick="selectTag('音乐')">音乐</a>
<a href="javascript:void(0)" onClick="selectTag('图片')">图片</a>
</div>
<span>
<input id="kw" type="text" value="" size="30"></input>
</span>
最终效果:点击<a>网页</a>标签后赋值给文本框,并把当前标签设为选中状态,即改字体为红色,当点击另一个标签<a>新闻</a>后则恢复上次被点击的颜色。