js 单击一个词,使这个词 变色和变粗, 如 东湖这个词是有链接的,我单击 东湖时,希望 东湖 二字能 变红色和变粗,怎么实现呀,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script> function change(obj){ obj.style.color="red"; obj.style.fontWeight=800; }</script><div onclick="change(this)">东湖</div> <!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=gb2312" /><title>无标题文档</title><script type="text/javascript"> window.onload = function(){ document.getElementById('a').onclick = function(){ this.style.color = 'red'; this.style.fontWeight = 'bold'; }; }</script></head><body> <a href="#" id="a">东湖</a></body></html> <script> var lastobj; function change(obj){ if(lastobj) { lastobj.style.color="black"; lastobj.style.fontWeight=200 } obj.style.color="red"; obj.style.fontWeight=800; lastobj=obj }</script><div onclick="change(this)">东湖</div><div onclick="change(this)">西湖</div> L@_@K<!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> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css">a{ color: blue;} </style> </head> <body> 我单击 <a href="#">东湖</a>时,希望 <a href="#">东湖</a> 二字能 变红色和变粗,怎么实现呀,谢谢<br /> <a href="#">东湖</a>、<a href="#">东湖</a>、<a href="#">东湖</a> </body> <script type="text/javascript"> <!--var cA = document.getElementsByTagName("a");for (var i=0; i<cA.length; i++){ cA[i].onclick = function(){ if (this != document.body.currentLink) { if(document.body.currentLink) { document.body.currentLink.style.color = ""; document.body.currentLink.style.fontWeight = 'normal'; } this.style.color = 'red'; this.style.fontWeight = 'bold'; document.body.currentLink = this; } };} //--> </script></html> 简单一点,用CSS就可以实现<html><head><style>a:link{ font-family:"宋体"; font-size:24px; color:#666666;}a:hover{ font-family:"宋体"; font-size:24px; color:blue;}a:visited{ font-family:"宋体"; font-size:24px; color:red; font-weight:bold;}</style></head><body><a href="#">东湖</a></body></html> a:link{}这里面的属性定义的是链接最开始的状态,鼠标还没有点击过 a:hover{}这里面的属性定义的是当鼠标放在这个连接上但是还没有点击的状态 a:visited{}这里面的属性定义的是鼠标点击过后的状态。鼠标点击过后会一直保持这个状态,除非刷新,或者删除浏览过的历史记录以后再刷新。如果你不需要那种状态可以删掉,每种状态可以根据自己的需求来设置css样式 我这里定义的是:鼠标还未点击时,链接文字是灰色,宋体,24px;鼠标经过时,链接文字是蓝色,宋体24px;鼠标点击过后,链接文字是红色,宋体,24px,加粗。楼主可以拿这段代码去试一试效果。 a:visited{font-weight:bold;}<a href="#" onclcik="this.style.fontWeigh=400" 一看楼主的需求,就知道要用css做,这是最好的做法。顶9楼 像这类操作最好就是用CSS CSS能解决的问题就不要用js js和css都可以解决,就看楼主需要怎样了 JQUERY中怎么进行元素的二次查找? 高手帮忙,超链接点击后,效果无法停留 jquery如何得到表格第一行? HTC中 element.parentNode.removeChild(element)自己删除自己 如何使手机页面与电脑页面一样 这个cookies怎么改写成javascript server 断的? 一个表格有两行,各有一个radio按钮,如何做到点一个按钮时两行的文字都变成其他颜色 怎样用JS在DIV上贴图 各位帮忙啊.一个问题. 一个小问题,如何实现? 关于span的disabled禁用属性 JS中如何根据值执行代码
<script>
function change(obj){
obj.style.color="red";
obj.style.fontWeight=800;
}
</script>
<div onclick="change(this)">东湖</div>
<!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=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
window.onload = function(){
document.getElementById('a').onclick = function(){
this.style.color = 'red';
this.style.fontWeight = 'bold';
};
}
</script>
</head><body>
<a href="#" id="a">东湖</a>
</body>
</html>
<script>
var lastobj;
function change(obj){
if(lastobj) {
lastobj.style.color="black";
lastobj.style.fontWeight=200
}
obj.style.color="red";
obj.style.fontWeight=800;
lastobj=obj
}
</script>
<div onclick="change(this)">东湖</div><div onclick="change(this)">西湖</div>
<!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>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
a
{
color: blue;
} </style>
</head> <body>
我单击 <a href="#">东湖</a>时,希望 <a href="#">东湖</a> 二字能 变红色和变粗,怎么实现呀,谢谢<br />
<a href="#">东湖</a>、<a href="#">东湖</a>、<a href="#">东湖</a>
</body>
<script type="text/javascript">
<!--
var cA = document.getElementsByTagName("a");
for (var i=0; i<cA.length; i++)
{
cA[i].onclick = function(){
if (this != document.body.currentLink)
{
if(document.body.currentLink)
{
document.body.currentLink.style.color = "";
document.body.currentLink.style.fontWeight = 'normal';
} this.style.color = 'red';
this.style.fontWeight = 'bold'; document.body.currentLink = this;
}
};
}
//-->
</script>
</html>
<head>
<style>
a:link{
font-family:"宋体";
font-size:24px;
color:#666666;
}
a:hover{
font-family:"宋体";
font-size:24px;
color:blue;
}
a:visited{
font-family:"宋体";
font-size:24px;
color:red;
font-weight:bold;
}
</style>
</head>
<body>
<a href="#">东湖</a>
</body>
</html> a:link{}这里面的属性定义的是链接最开始的状态,鼠标还没有点击过
a:hover{}这里面的属性定义的是当鼠标放在这个连接上但是还没有点击的状态
a:visited{}这里面的属性定义的是鼠标点击过后的状态。鼠标点击过后会一直保持这个状态,除非刷新,或者删除浏览过的历史记录以后再刷新。如果你不需要那种状态可以删掉,每种状态可以根据自己的需求来设置css样式
{
font-weight:bold;
}
<a href="#" onclcik="this.style.fontWeigh=400"