본문 바로가기

Web/javascript & jQuery

랜덤으로 이미지 출력하기

반응형
function randomImage(){
    var bannerImages=new Array();
        bannerImages[0]="이미지경로";
        bannerImages[1]="";
        bannerImages[2]="";
    var bannerlink = new Array();
        bannerlink[0] = "링크";
        bannerlink[1] = "";
        bannerlink[2] = "";
    var bannerTitle = new Array();
        bannerTitle[0] = "";
        bannerTitle[1] = "";
        bannerTitle[2] = "";
    var bannerAlt = new Array();
        bannerAlt[0] = "";
        bannerAlt[1] = "";
        bannerAlt[2] = "";
  
    var ranNum=Math.floor(Math.random()*bannerImages.length);
  
    $('이미지를 감싸는 요소').attr({src : bannerImages[ranNum],
                alt: bannerAlt[ranNum]});
    $('이미지링크').attr({href : bannerlink[ranNum],
                title: bannerTitle[ranNum]});
                 
}
randomImage();
function randomImage(){
    var bannerImages=new Array();
        bannerImages[0]="이미지경로";
        bannerImages[1]="";
        bannerImages[2]="";
    var bannerlink = new Array();
        bannerlink[0] = "링크";
        bannerlink[1] = "";
        bannerlink[2] = "";
    var bannerTitle = new Array();
        bannerTitle[0] = "";
        bannerTitle[1] = "";
        bannerTitle[2] = "";
    var bannerAlt = new Array();
        bannerAlt[0] = "";
        bannerAlt[1] = "";
        bannerAlt[2] = "";
 
    var ranNum=Math.floor(Math.random()*bannerImages.length);
 
    $('이미지를 감싸는 요소').attr({src : bannerImages[ranNum],
                alt: bannerAlt[ranNum]});
    $('이미지링크').attr({href : bannerlink[ranNum],
                title: bannerTitle[ranNum]});
                
}
randomImage();


반응형