0
这是我如何调用Java脚本函数在我的HTML页面: -图片滚动不工作
<script type="text/javascript" src="imagerollover.js"></script>
</script>
<script type="text/javascript">
//Following function should be called at the end of the page:
imagerollover();
</script>
</head>
<body>
.
.
.
这是我imagerollover.js: -
function imagerollover(){
var allimages=document.getElementsByTagName("img")
var preloadimages=[]
for (var i=0; i<allimages.length; i++){
if (allimages[i].getAttribute("data-over")){ //if image carries "data-over" attribute
preloadimages.push(new Image()) //preload "over" image
preloadimages[preloadimages.length-1].src=allimages[i].getAttribute("data-over")
allimages[i].onmouseover=function(){
this.src=this.getAttribute("data-over")
}
allimages[i].onmouseout=function(){
this.src=this.getAttribute("data-out")
}
} //end if
} //end for loop
}
//Usage: Call following function at the end of the page:
//imagerollover()
图片代码:
<img src="knitting1.jpg"
data-over="knitting2.jpg"
data-out="knitting1.jpg"
alt="Logo" width="400px" height="90" align="middle" />
此外,我的网站的根文件夹中存在两个图像knitting1.jpg和knitting2.jpg。我不知道什么是错的。请帮忙。谢谢。
我在开始的时候放置一个警告imagerollover.js文件中。它正在呼叫,但它没有显示任何翻滚效果。为什么?
你的''标签是什么样子? – Blender 2012-08-19 05:27:36
– Serenity 2012-08-19 05:36:30