页面上动态生成几个连接,怎么才能让当一个选中其它的恢复原来的样式 我对javascirpt不是很懂,楼上说的没明白,我是想这么做,给每个连接加一个onclick事件在事件中首先将页面所有连接还原为默认色,然后把当前选种的设为不同色,不知道能不能实现,如果能怎么实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function changestyle() { for(i=0;i<document.links.length;i++) { document.links(i).style.color = 'blue'; } this.style.color= 'red'; window.alert('hello'); } function setstyle() { for(i=0;i<document.links.length;i++) { document.links(i).style.color = 'blue'; } }怎么使当前选中的样式改变,我用this不行 <a href=#>1111</a><br><a href=#>2222</a><br><a href=#>3333</a><br><a href=#>44444</a><SCRIPT LANGUAGE="JavaScript"><!--var _mm = null;document.onclick = function(){ var e = window.event.srcElement; if(e.tagName == "A") { e.style.backgroundColor = "yellow"; if(_mm) _mm.style.backgroundColor = ""; _mm = e; }}//--></SCRIPT> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta name="Generator" content="EditPlus"><meta name="Author" content="Seagle.K"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><base target="_blank"><script language="JavaScript">var lastlink;function bindclick(){ var o = document.getElementsByTagName('a'); for (var i=0; i<o.length; i++) { o[i].attachEvent("onclick", new Function("aclick()")); }}function aclick(){ var srcElement = event.srcElement; srcElement.className="special"; if (typeof(lastlink) != 'undefined') { lastlink.className=""; } lastlink=srcElement;}</script><style type="text/css">a.special:link { text-decoration: none; color: red; } a.special:active { text-decoration: none; color: red; } a.special:visited { text-decoration: none; color: red; } a.special:hover { text-decoration: none; color: red; } a:link { text-decoration: underline; color: black; }a:active { text-decoration: underline; color: black; }a:visited { text-decoration: underline; color: black; }a:hover { text-decoration: underline; color: black; }</style></head><body onload="bindclick()"><a href="http://www.blogcn.com/user2/eosin/index.html">go</a><br><a href="http://www.blogcn.com/user2/eosin/index.html">goo</a><br><a href="http://www.blogcn.com/user2/eosin/index.html">gooo</a></br><a href="http://www.blogcn.com/user2/eosin/index.html">goooo</a></br><a href="http://www.blogcn.com/user2/eosin/index.html">gooooo</a></br></body></html> google map最大路标数问题 笨鸟问一个比较弱的问题? 谁能实现“拖动网页内部元素,使浏览器窗口移动”只需要支持IE即可 [原创/分享/散分] 模拟Vista窗口效果(酷) - 另小站改版 请帮我解释一下下面的代码的整个逻辑,谢谢! 一個很小的問題﹐菜鳥菜﹐沒有辦法﹐大家幫幫我吧 请问大家在做界面时遵循什么规范?对此事有什么自己的看法? 请问用window.open()函数打开一个窗口时,如何使新窗口全屏? 为什么我的css代码不能够使边框的某个方向的边消失? 急!急!急!急!如何替换字符串中的反斜杠'\' 天,这是为什么啊,这是为什么呢? js脚本解密
{
for(i=0;i<document.links.length;i++)
{
document.links(i).style.color = 'blue';
}
this.style.color= 'red';
window.alert('hello');
}
function setstyle()
{
for(i=0;i<document.links.length;i++)
{
document.links(i).style.color = 'blue';
}
}
怎么使当前选中的样式改变,我用this不行
<a href=#>2222</a><br>
<a href=#>3333</a><br>
<a href=#>44444</a><SCRIPT LANGUAGE="JavaScript">
<!--
var _mm = null;
document.onclick = function()
{
var e = window.event.srcElement;
if(e.tagName == "A")
{
e.style.backgroundColor = "yellow";
if(_mm) _mm.style.backgroundColor = "";
_mm = e;
}
}
//-->
</SCRIPT>
<html>
<head>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="Seagle.K">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base target="_blank">
<script language="JavaScript">
var lastlink;function bindclick()
{
var o = document.getElementsByTagName('a');
for (var i=0; i<o.length; i++)
{
o[i].attachEvent("onclick", new Function("aclick()"));
}
}function aclick()
{
var srcElement = event.srcElement;
srcElement.className="special";
if (typeof(lastlink) != 'undefined')
{
lastlink.className="";
}
lastlink=srcElement;
}
</script>
<style type="text/css">
a.special:link { text-decoration: none; color: red; }
a.special:active { text-decoration: none; color: red; }
a.special:visited { text-decoration: none; color: red; }
a.special:hover { text-decoration: none; color: red; } a:link { text-decoration: underline; color: black; }
a:active { text-decoration: underline; color: black; }
a:visited { text-decoration: underline; color: black; }
a:hover { text-decoration: underline; color: black; }
</style>
</head>
<body onload="bindclick()">
<a href="http://www.blogcn.com/user2/eosin/index.html">go</a><br>
<a href="http://www.blogcn.com/user2/eosin/index.html">goo</a><br>
<a href="http://www.blogcn.com/user2/eosin/index.html">gooo</a></br>
<a href="http://www.blogcn.com/user2/eosin/index.html">goooo</a></br>
<a href="http://www.blogcn.com/user2/eosin/index.html">gooooo</a></br>
</body>
</html>