日期:2014-05-16  浏览次数:20335 次

关于js闪烁字效果的问题
我想做一个标题闪烁字的效果,但是标题是闪烁的,但是点击标题没反应,右击标题,然后选择打开却又可以打开链接,具体代码如下,各位大侠帮我改改
<html>

<body>
<table>
</script>
<tr><td>hhx</td><td><a href="http://www.baidu.com"><script language="JavaScript">
<!-- Begin
text = "欢迎您光临"; //显示的文字
color1 = "blue"; //文字的颜色
color2 = "red"; //转换的颜色
style ="font-size:15pt"; //字体大小
speed = 100; //转换速度 (1000 = 1 秒)
i = 0;
if (navigator.appName == "Netscape") {
document.write("<layer id=a visibility=show></layer><br><br><br>");}
else {document.write("<div id=a></div>");}
function changeCharColor() {
if (navigator.appName == "Netscape") {
document.a.document.write("<center><font face=arial style =" + style + "><font color=" + color1 + ">");
for (var j = 0; j < text.length; j++) {
if(j == i) {document.a.document.write("<font face=arial color=" + color2 + ">" + Text.charAt(i) + "</span></font>");}
else {document.a.document.write(text.charAt(j));}}
document.a.document.write('</span></font></span></font></center>');
document.a.document.close();}
if (navigator.appName == "Microsoft Internet Explorer") {
str = "<center><font face=arial style =" + style + "><font color=" + color1 + ">";
for (var j = 0; j < text.length; j++) {if( j == i) {str += "<font face=arial color=" + color2 + ">" + text.charAt(i) + "</span></font>";}
else {str += text.charAt(j);}}str += "</span></font></span></font></center>";
a.innerHTML = str;}(i == text.length) ? i=0 : i++;}setInterval("changeCharColor()", speed);
// End -->
</script></a>
</td></tr></table>
</body>
</html>

------解决方案--------------------
<a id='a_baidu' href="http://www.baidu.com" style='color:blue' target='_black'>baidu</a>
<script>
var a_baidu = document.getElementById("a_baidu");
var isBlue=true;
setInterval(function()
{

a_baidu.style.color = isBlue ?"red":"blue";
isBlue=!isBlue;
},300);
</script>