注册 登录
编程论坛 ASP技术论坛

网页中两个<body onload= >如何修改才能不冲突?

小狐001 发布于 2010-09-26 13:25, 2641 次点击
首页调用的头文件top.asp中有个<body onload=init();>
调用的图片转换页面tupian.asp里也有个<body onload=swcpic();>
这样导致图片转换页面无法显示内容,
请问这种情况应该如何修改?是否有<table> 加载触发函数的命令?

10 回复
#2
孤独冷雨2010-09-26 13:41
你的top文件做的有问题吧?不然怎么会在一个页面里有两<body>。
#3
小狐0012010-09-26 13:47
是调用啊,首页调用了两个页面,这两个页面里都有<body>
#4
小狐0012010-09-26 14:07
我把图片转换页的代码贴出来吧:
<!--#include file = inc/conn.asp -->
<script language=javascript>
isns = navigator.appName == "Netscape";
function ztstr(id,picurl,linkurl)
{
this.id=id
this.picurl=picurl
this.linkurl=linkurl
}

zhuanti=new Array()
imgcount=1;
frequency=10*1000;//10秒

<%set rss=Server.CreateObject("ADODB.Recordset")
sqls="select top 6 id,title,pic,lm,lm2,lm3 from news where ( pic like '%.jpg%' or pic like '%.JPG%' ) and sh=1  order by [time] desc"
set rss=conn.Execute(sqls)
counter=1
if rss.bof and rs.eof then
response.Write("<br><li>内容正在添加...</li>")
else
do while not rss.eof
%>
zhuanti[<%=counter%>]=new ztstr('<%=counter%>','<%=rss("pic")%>','news_view.asp?newsid=<%=rss("ID")%>')
<%
counter=counter+1
rss.movenext
loop
end if
rss.close
set rss=nothing
%>
imgcount=zhuanti.length-1
for(i=1;i<=imgcount;i++)
{
eval("img"+i+"=new Image()")
eval("img"+i+".src=zhuanti["+i+"].picurl")
}

nn=1

var rand1 = 0;
var useRand = 0;

function swapPic() {
var imgnum = zhuanti.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
// alert(useRand);
nn=useRand;
change_img();
}

function change_img()
{
eval('document.pic.src=img'+nn+'.src');
nn++;
if(nn>imgcount) nn=1
if(!isns)
{
pic.filters.item(0).apply()
pic.style.visibility='visible'
pic.filters.item(0).play()
setTimeout("pic.style.visibility='hidden'",frequency);
}
else
document.pic.visibility='visible'
tt=setTimeout('change_img()',frequency)
}

function pictarget()
{
tt=nn-1
if(tt<1) tt=imgcount
cururl=zhuanti[tt].linkurl
window.open(cururl);
}
function ini()
{
if(!isns)
{
spacewidth=Math.round((divmask.offsetWidth-770)/2)
dmwidth=770+spacewidth
dmheight=divmask.offsetHeight
totalstep=50
timeout=50
dmstepw=Math.round(770/totalstep)
dmsteph=Math.round(dmheight/totalstep)
setTimeout('hidimg()',3000)
}
else swapPic()
}

function hidimg()
{
dmwidth-=dmstepw
dmheight-=dmsteph
eval('divmask.style.clip="rect(0,'+dmwidth+','+dmheight+',0)"')
hdrun=setTimeout('hidimg()',timeout)
if(dmwidth<=spacewidth&&dmheight<=0)
{
divmask.style.visibility='hidden'
clearTimeout(hdrun)
swapPic()
}
}
</script>

<script language="javascript" >
swapPic();
</script>
<body onload=swapPic();> ////就是这里,我现在要不用onload而能调用这个函数
<table>
<tr><td>
<a href=javascript:void(null) onclick='javascript:pictarget();return false;'><img src="" width=183 height=124 border=0 name=pic style="visibility:hidden;filter:revealtrans(duration=2.0,transition=12)"></a>
</td></tr>
</table>
#5
小狐0012010-09-26 15:25
没有人能帮我解决这个问题吗?
#6
hams2010-09-26 15:32
不能有两个,需要把其中的一个去掉。
#7
小狐0012010-09-26 15:35
我知道要去掉其中一个,问题是怎么去?
#8
hams2010-09-26 18:05
这个问题好难回答……
#9
小狐0012010-09-26 18:11
帮忙啊……55555
#10
wangjy5002010-09-26 23:35
将swapPic()放在前一个里面不就可了
#11
yms1232010-09-27 14:09
body onload=init();>
<body onload=swcpic();>
先执行init再执行swcpic()?
这两个页面是include引用到首页的还是iframe嵌入到首页的?
1