PHP 페이지 열때마다 Random 이미지 보이기
페이지 정보
본문
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#banner {margin: 0; padding: 0; list-style-type: none;}
img {border: 0;}
</style>
<script type="text/javascript">
function randomBanner() {
var bannerBox = document.getElementById('banner');
var bannerImg = bannerBox.getElementsByTagName('li');
var randomNum = Math.floor((Math.random() * bannerImg.length));
for (var i = 0; i<bannerImg.length; i++) {
bannerImg[i].style.display = 'none';
}
bannerImg[randomNum].style.display = 'block';
}
</script>
</head>
<body>
<ul id="banner">
<li><a href="http://google.com"><img src="img1.jpg" alt="" /></a></li>
<li><a href="http://microsoft.com"><img src="img2.jpg" alt="" /></a></li>
<li><a href="https://www.happyjung.com"><img src="img3.jpg" alt="" /></a></li>
</ul>
<script type="text/javascript">
randomBanner("banner");
</script>
</body>
</html>
참고자료
http://webuit.tistory.com/70
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#banner {margin: 0; padding: 0; list-style-type: none;}
img {border: 0;}
</style>
<script type="text/javascript">
function randomBanner() {
var bannerBox = document.getElementById('banner');
var bannerImg = bannerBox.getElementsByTagName('li');
var randomNum = Math.floor((Math.random() * bannerImg.length));
for (var i = 0; i<bannerImg.length; i++) {
bannerImg[i].style.display = 'none';
}
bannerImg[randomNum].style.display = 'block';
}
</script>
</head>
<body>
<ul id="banner">
<li><a href="http://google.com"><img src="img1.jpg" alt="" /></a></li>
<li><a href="http://microsoft.com"><img src="img2.jpg" alt="" /></a></li>
<li><a href="https://www.happyjung.com"><img src="img3.jpg" alt="" /></a></li>
</ul>
<script type="text/javascript">
randomBanner("banner");
</script>
</body>
</html>
참고자료
http://webuit.tistory.com/70
댓글목록
등록된 댓글이 없습니다.