如何在javsscript中的图片中添加href

时间:2019-07-26 15:10:47

标签: javascript html

嗨,我想知道如何在JavaScript函数中为我的照片添加href。 我想将每张照片连接到某个网站,但我不知道该怎么办

<body onload="showRandomImage()">
    <img id="myimage" />


<script type="text/javascript">
function showRandomImage() {
        var theImage = document.getElementById('myimage');
        var thePath = 'images/';
 var thePictures = new Array();
    thePictures[0] = 'photo1.jpg';
    thePictures[1] = 'photo2.jpg';
    thePictures[2] = 'photo3.jpg';
    thePictures[3] = 'photo4.jpg';
    thePictures[4] = 'photo5.jpg';
    thePictures[5] = 'photo6.jpg';
    thePictures[6] = 'photo7.jpg';

    var theTime = new Date();
    var theWeekday = theTime.getDay();

    var imagePath = thePath + thePictures[theWeekday];

    theImage.src = imagePath;
    theImage.alt = thePictures[theWeekday];
    theImage.title = thePictures[theWeekday];
 }
</script>

0 个答案:

没有答案