我有这段代码可以创建图片的幻灯片。唯一的问题是,它不能正确放置在网站上:图片的循环未正确放置在网站上
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var pictureArchive= ['http://byggprojektoren.se/wp-content/uploads/2014/09/Shanghai.jpg','http://byggprojektoren.se/wp-content/uploads/2014/06/logo_739047_web.jpg','3.jpg','4.jpg'];
window.onload=function() {
var o=document.createElement('img');
o.setAttribute('id', 'image');
o.setAttribute('src', pictureArchive[0]);
o.setAttribute('alt', '');
document.body.appendChild(o);
rotate(pictureArchive.length);
}
function rotate(idx) {
if(idx>=pictureArchive.length) {
idx=0;
}
document.getElementById('image').src=pictureArchive[idx++];
timerID=setTimeout('rotate('+idx+')', 3000);
}
</script>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>
网址:Website
中的代码我在哪里写是错误的放置图片的地方是现在呢?
希望得到任何帮助。谢谢。
事情是,我使用的Wordpress主题,它自动把它放在我想要它的位置。有没有什么办法可以将** document.body.appendChild(o)**拿走,然后自动将它正确放置?谢谢你或你的回复。 – RiMa 2014-09-18 17:34:54
document.body.appendChild(o);将永远追加到你已经附加到身体的任何其他地方 - 如果你用document.body.appendChild()创建你的整个页面,你可以将它插入到正确的位置 - 或者你可以使用CSS来强制更好的位置 – 2014-09-18 17:36:10
好的,谢谢你或这个帮助。我尝试过,但由于某种奇怪的原因,图像消失了。 – RiMa 2014-09-18 18:00:33