紧急求救:一个javascript问题
<!doctypehtmlpublic"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 530;
this.minHeigth=nMinHth || 1;
this.state=sState || "down" ;
var obj = document.getElementById(id);
if(intervalId != null)window.clearInterval(intervalId);
function openBox(){
var h = obj.offsetHeight;
obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px";
if(obj.offsetHeight>this.maxHeigth){
window.clearInterval(intervalId);
intervalId=window.setInterval(closeBox,this.stayTime);
}
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,10);
}
</script>
<body style="margin:0;padding:0;font-size:14px;">
<div id="MyMoveAd" style="background:;height:12px;overflow:hidden;"><img src="1.jpg" width="1000" height="530"></div>
<script type="text/javascript">
<!--
slideAd('MyMoveAd',1);
-->
</script>
_________________________________________________________________以上是一个JAVA脚本广告伸缩代码.我将它插入到我网站首页里,但出现错误,网站文字颜色由白色变成了黑色,一些框架位置也发生了变化.严重影响美观...找了半天发现了毛病所在,原来是句"<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> " 问题..如果将这句头部说明语句去掉,再将代码插入到网站里,一切正常..但代码去变成了无限循环.图片不断出现再出现.
我现在想的是,能不能将<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 去掉....让它无限循环,,在代码能不能加一个让它循环一次的语句,,,在下对JAVA也不是很熟悉.研究了一晚上也没弄出来...
急盼各位高手,指点...
(<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 必须去掉这句,让它只循环一次) 展开
<script type="text/javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 530;
this.minHeigth=nMinHth || 1;
this.state=sState || "down" ;
var obj = document.getElementById(id);
if(intervalId != null)window.clearInterval(intervalId);
function openBox(){
var h = obj.offsetHeight;
obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px";
if(obj.offsetHeight>this.maxHeigth){
window.clearInterval(intervalId);
intervalId=window.setInterval(closeBox,this.stayTime);
}
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,10);
}
</script>
<body style="margin:0;padding:0;font-size:14px;">
<div id="MyMoveAd" style="background:;height:12px;overflow:hidden;"><img src="1.jpg" width="1000" height="530"></div>
<script type="text/javascript">
<!--
slideAd('MyMoveAd',1);
-->
</script>
_________________________________________________________________以上是一个JAVA脚本广告伸缩代码.我将它插入到我网站首页里,但出现错误,网站文字颜色由白色变成了黑色,一些框架位置也发生了变化.严重影响美观...找了半天发现了毛病所在,原来是句"<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> " 问题..如果将这句头部说明语句去掉,再将代码插入到网站里,一切正常..但代码去变成了无限循环.图片不断出现再出现.
我现在想的是,能不能将<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 去掉....让它无限循环,,在代码能不能加一个让它循环一次的语句,,,在下对JAVA也不是很熟悉.研究了一晚上也没弄出来...
急盼各位高手,指点...
(<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 必须去掉这句,让它只循环一次) 展开
1个回答
展开全部
<script type="text/javascript">
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 530;
this.minHeigth=nMinHth || 3;
this.state=sState || "down" ;
var obj = document.getElementById(id);
if(intervalId != null)window.clearInterval(intervalId);
function openBox(){
var h = obj.offsetHeight;
obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px";
if(obj.offsetHeight>this.maxHeigth){
window.clearInterval(intervalId);
intervalId=window.setInterval(closeBox,this.stayTime);
}
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,10);
}
</script>
<body style="margin:0;padding:0;font-size:14px;">
<div id="MyMoveAd" style="background:;height:12px;overflow:hidden;"><img src="1.jpg" width="1000" height="530"></div>
<script type="text/javascript">
<!--
slideAd('MyMoveAd',1);
-->
</script>
<div id="Result"></div>
改了。我把你最小高度,也就是你slideAd方法中的this.minHeigth=nMinHth || 3; 在不赋值的情况下默认为了3.
因为在不加XHTML规则的时候obj.style.height是取不到0的,当取到0的时候实际的offsetHeight会变成obj.style.height的初始值,也就是530。所以最终导致
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
永远无法执行。
var intervalId = null;
function slideAd(id,nStayTime,sState,nMaxHth,nMinHth){
this.stayTime=nStayTime*1000 || 3000;
this.maxHeigth=nMaxHth || 530;
this.minHeigth=nMinHth || 3;
this.state=sState || "down" ;
var obj = document.getElementById(id);
if(intervalId != null)window.clearInterval(intervalId);
function openBox(){
var h = obj.offsetHeight;
obj.style.height = ((this.state == "down") ? (h + 2) : (h - 2))+"px";
if(obj.offsetHeight>this.maxHeigth){
window.clearInterval(intervalId);
intervalId=window.setInterval(closeBox,this.stayTime);
}
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
}
function closeBox(){
slideAd(id,this.stayTime,"up",nMaxHth,nMinHth);
}
intervalId = window.setInterval(openBox,10);
}
</script>
<body style="margin:0;padding:0;font-size:14px;">
<div id="MyMoveAd" style="background:;height:12px;overflow:hidden;"><img src="1.jpg" width="1000" height="530"></div>
<script type="text/javascript">
<!--
slideAd('MyMoveAd',1);
-->
</script>
<div id="Result"></div>
改了。我把你最小高度,也就是你slideAd方法中的this.minHeigth=nMinHth || 3; 在不赋值的情况下默认为了3.
因为在不加XHTML规则的时候obj.style.height是取不到0的,当取到0的时候实际的offsetHeight会变成obj.style.height的初始值,也就是530。所以最终导致
if (obj.offsetHeight<this.minHeigth){
window.clearInterval(intervalId);
obj.style.display="none";
}
永远无法执行。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询