如何实现onclick点击后,字体变色

你们都是坏人 2009-07-06 08:34:46
如下所示,当点击参数1时对应的参数1变色其他参数2、3、4不变色!
<div style="width:140px;line-height:25px;">
<a href="javascript:document.form1.submit();" onclick="orderb('edu1','1')" >参数1</a>
</div>
<div style="width:140px;line-height:25px;">
<a href="javascript:document.form1.submit();" onclick="orderb('edu1','2')" >参数2</a>
</div>
<div style="width:140px;line-height:25px;">
<a href="javascript:document.form1.submit();" onclick="orderb('edu1','3')" >参数3</a>
</div>
<div style="width:140px;line-height:25px;">
<a href="javascript:document.form1.submit();" onclick="orderb('edu1','4')" >参数4</a>
</div>
...全文
810 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Coding_Playing_Boy 2009-07-10
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.MenuNormal
{
color: Black;
}
.MenuSel
{
color: Red;
}
</style>

<script>
function fnSel(obj, bIsSel) {
if (bIsSel) {
obj.className = "MenuSel";
}
else {
obj.className = "MenuNormal";
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div style="width: 140px; line-height: 25px;">
<a onmouseover="fnSel(this,true)" onmouseout="fnSel(this,false)">参数1 </a>
</div>
<div style="width: 140px; line-height: 25px;">
<a onmouseover="fnSel(this,true)" onmouseout="fnSel(this,false)">参数2 </a>
</div>
<div style="width: 140px; line-height: 25px;">
<a onmouseover="fnSel(this,true)" onmouseout="fnSel(this,false)">参数3 </a>
</div>
<div style="width: 140px; line-height: 25px;">
<a onmouseover="fnSel(this,true)" onmouseout="fnSel(this,false)">参数4 </a>
</div>
</form>
</body>
</html>

ok???
cceon 2009-07-10
  • 打赏
  • 举报
回复
学习
蝶恋花雨 2009-07-09
  • 打赏
  • 举报
回复
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
<script type="text/javascript">
function BackgroundColor()//点击字体颜色变化
{
var q = 4; for (i = 1; i < 4; i++)
{ if (document.getElementById("hr" + i) != null) { document.getElementById("hr" + i).style.color = ''; } }
}
</script>
</head>

<body>
<div style="margin:0 auto" align="center"><input type="text"/><input type="text"/></div>
<div style="margin-left:auto;margin-right:auto" align="center"><input type="text"/><input type="text"/></div>
<div style="width:140px;line-height:25px;">
<a id="hf1" href="#" onclick="BackgroundColor();this.style['color']='red'" >参数1 </a>
</div>
<div style="width:140px;line-height:25px;">
<a id="hf2" href="#" onclick="BackgroundColor();this.style['color']='#333333'" >参数2 </a>
</div>
<div style="width:140px;line-height:25px;">
<a id="hf3" href="#" onclick="BackgroundColor();this.style['color']='#333333'" >参数3 </a>
</div>
<div style="width:140px;line-height:25px;">
<a id="hf4" href="#" onclick="BackgroundColor();this.style['color']='#333333'" >参数4 </a>
</div>
</body>

</html>


"orderb('edu1','2')"你的方法自己调调。我这里没你的方法所以删除了。自己加
chowyi 2009-07-06
  • 打赏
  • 举报
回复
变了色你也看不了啊
mrshelly 2009-07-06
  • 打赏
  • 举报
回复
a:visited {color:#f00;}
william3033 2009-07-06
  • 打赏
  • 举报
回复
声明一个外部变量保存上次点击的<a>对象 var last = null;
a的onclick = setColor(this)
function setColor(o){
o.style.color = "...";
if(last!=null)
last.style.color = "";
last = o;
}

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧