点击循环显示图片

<!DOCTYPE html>
<html>
<head>
    <title>picture</title>
</head>
<body>
        <button onclick="showPicture()" type="button" style="border: 1px solid #ffffff;padding: 0px;">
            <img id="img1" src="pictures/heying0_1.png" width="600" height="450" align="right">
        </button>
    <script type="text/javascript">
        function showPicture(){
            if (typeof(Storage)!=="undefined") {
                if (sessionStorage.clickcount) {
                    sessionStorage.clickcount=Number(sessionStorage.clickcount)+1;
                }else{
                    sessionStorage.clickcount=1;
                }
                //document.getElementById("im").innerHTML="点击按钮 "+sessionStorage.clickcount+"次。";
                document.getElementById("img1").src="pictures/heying0_"+String((sessionStorage.clickcount)%4+1)+".png";
            }else{
                //如果不支持web存储,设置一个默认的
                document.getElementById("img1").src="pictures/heying0_1.png";
            }
        }
    </script>


</body>
</html>
全部评论

相关推荐

08-21 10:58
延安大学 C++
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
08-14 22:16
我爱加瓦233:今年行情真的好起来了,暑期实习拿了美团,京东,饿了么三家的Offer,最终去了美团,披上了我的黄马褂,开启送外卖之旅
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务