都不知道你的js长什么样子!!发几个美女,又无法看到本质的东西(code),谁知道你代码哪个地方出问题了呢!!
js放在了html源码中呀
@样_样: 大侠,“html源码” 这个,我怎么才看到呢??在哪里??
<!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>纯JS实现的skype中文6屏焦点图片切换效果 - 分享JavaScript-www.websbook.com</title>
<meta name="Copyright" content="JavaScript分享网 http://www.websbook.com/" />
<meta name="description" content="纯JS实现的skype中文6屏焦点图片切换效果,JavaScript分享网" />
<meta content="JavaScript,分享,JavaScript代码,Ajax" name="keywords" />
<style type="text/css">
/* 懒人图库 搜集整理 www.lanrentuku.com */
#NewsPic { BORDER-TOP-WIDTH: 0px; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; BORDER-LEFT-WIDTH: 0px; LEFT: 0px; BORDER-BOTTOM-WIDTH: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; WIDTH: 368px; PADDING-TOP: 0px; POSITION: relative; TOP: 0px; HEIGHT: 300px; BORDER-RIGHT-WIDTH: 0px}
#NewsPicTxt { BORDER-TOP-WIDTH: 1px; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-WEIGHT: bold; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 12px; BORDER-BOTTOM-WIDTH: 1px; PADDING-BOTTOM: 0px; MARGIN: 3px auto 0px; WIDTH: 365px; COLOR: black; PADDING-TOP: 0px; FONT-FAMILY: Sans-Serif; POSITION: relative; HEIGHT: 0px; TEXT-ALIGN: center; BORDER-RIGHT-WIDTH: 1px}
#NewsPicTxt A { COLOR: black; TEXT-DECORATION: none}
#NewsPicTxt A:hover { COLOR: black; TEXT-DECORATION: none}
#NewsPicTxt A:visited { COLOR: black; TEXT-DECORATION: none}
#NewPicTxt A:link { COLOR: black; TEXT-DECORATION: none}
#NewsPicTxt A:hover { COLOR: red}
#NewsPic A { BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; TEXT-DECORATION: none}
#NewsPic A:hover { TEXT-DECORATION: none}
#NewPic A:visited { TEXT-DECORATION: none}
#NewsPic .Picture { BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; LEFT: 0px; BORDER-LEFT: #ffffff 1px solid; WIDTH: 100%; BORDER-BOTTOM: #ffffff 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 100%}
#NewsPic .Nav { RIGHT: 0px; WIDTH: 100%; BOTTOM: 0px; POSITION: absolute; HEIGHT: 12px}
#NewsPic .Nav SPAN { DISPLAY: block; BACKGROUND: #000000; FLOAT: right; FONT: 10px Courier; BORDER-LEFT: #ffffff 1px solid; WIDTH: 24px; CURSOR: hand; COLOR: #ffffff; HEIGHT: 100%; TEXT-ALIGN: center}
#NewsPic .Nav SPAN.Cur { BACKGROUND: #019fe8; COLOR: white}
#NewsPic .Nav SPAN.Normal { BACKGROUND: #000000; FILTER: Alpha(opacity=50); COLOR: white; opacity: .5}
#NewsPic .Nav SPAN A { DISPLAY: block; WIDTH: 100%; COLOR: white; POSITION: relative; HEIGHT: 100%}
#NewsPic .Nav SPAN A:hover { CURSOR: hand}
</style>
<script>
var isIE=!(navigator.userAgent.indexOf('MSIE')==-1);
var news;
var curNew=0;
var timer;
function init() //初始化所有标签内容
{
var div=document.getElementById("NewsPic");
if(!div)return;
var nav=document.createElement("DIV");
nav.className="Nav";
var nodes;
if(isIE)
{
nodes=div.childNodes;
}
else
{
nodes=childrenNodes(div.childNodes);
}
news=new Array(nodes.length);
for(var i=nodes.length-1;i>=0;i--)
{
var element=nodes[i];
news[i]={};
news[i].Element=element;
news[i].Text=element.getAttribute("title");
news[i].Url=element.getAttribute("href");
var n=document.createElement("span");
n.innerHTML="<a herf=\"javascript:;\" onclick=\"javascript:curNew="+(i-1)+";change();\">"+(i+1)+"</a>";
if(i==curNew)n.className="Cur";
nav.appendChild(n);
news[i].LinkElement=n;
}
div.appendChild(nav);
curNew--;
change();
}
function childrenNodes(node)
{
var c=new Array();
for(var i=0;i<node.length;i++)
{
if(node[i].nodeName.toLowerCase()=="a")
c.push(node[i]);
}
return c;
}
function change()
{
var div=document.getElementById("NewsPic");
var text=document.getElementById("NewsPicTxt");
if(!div)return;
curNew=curNew+1;
if(curNew>=news.length)curNew=0;
for(var i=0;i<news.length;i++)
{
if(i==curNew)
{
news[i].Element.style.display="block";
news[i].Element.style.visibility="visible";
news[i].LinkElement.className="Cur";
text.innerHTML="<a href=\""+news[i].Url+"\" title=\""+news[i].Text+"\" target=\"_blank\">"+news[i].Text+"</a>";
}
else
{
news[i].Element.style.visibility="hidden";
news[i].Element.style.display="none";
news[i].LinkElement.className="Normal";
}
}
if(timer)window.clearTimeout(timer);
timer=window.setTimeout("change()",3000);
}
</script>
<BODY>
<br>
<table width="368" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="368">
<DIV class="auto_2_left_1_2" style="MARGIN-TOP: 6px; WIDTH: 365px; HEIGHT: 300px">
<SPAN id=focuspic><DIV id=NewsPic>
<A title=www.websbook.com href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/01.jpg"></A><A title=www.websbook.com href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/02.jpg"></A><A title=www.websbook.com style="DISPLAY: none" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/03.jpg"></A><A title=www.websbook.com style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/04.jpg"></A><A title=懒人图库 style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/05.jpg"></A><A title=www.websbook.com style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/06.jpg"></A><DIV id=NewsPicTxt style="DISPLAY: none; VISIBILITY: hidden"></DIV></SPAN>
<SCRIPT language=javascript>init();</SCRIPT>
</DIV></td>
</tr>
</table>
<br><br>
<br>
<table width="368" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="368">
<DIV class="auto_2_left_1_2" style="MARGIN-TOP: 6px; WIDTH: 365px; HEIGHT: 300px">
<SPAN id=focuspic><DIV id=NewsPic>
<A title=www.websbook.com href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/01.jpg"></A><A title=www.websbook.com href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/02.jpg"></A><A title=www.websbook.com style="DISPLAY: none" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/03.jpg"></A><A title=www.websbook.com style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/04.jpg"></A><A title=懒人图库 style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/05.jpg"></A><A title=www.websbook.com style="DISPLAY: none; VISIBILITY: hidden" href="http://www.websbook.com/" target=_blank><IMG class="Picture" src="images/06.jpg"></A><DIV id=NewsPicTxt style="DISPLAY: none; VISIBILITY: hidden"></DIV></SPAN>
<SCRIPT language=javascript>init();</SCRIPT>
</DIV></td>
</tr>
</table>
<br><br>
</body>
</html>
@样_样: firebug一下
@Angkor: ??就是图片我没有上传,你能放几张图片在img文件夹里测一下效果。
原因是调用document.getElementById的方法时,如果页面上有多个相同名称的ID,它只会获取第一个元素,所以第二个被忽略了。
建议你重新封装下函数,并且用 不同ID来调用即可
还是用JQuery方便一点,把ID换成一个类属性,然后用类选择器去进行遍历或者筛选,有多个相同ID,只会取到第一个ID的元素