11.15课堂作业-完成Coding Coffee产品页的like功能,鼠标点击事件

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CODING COFFEE</title>

<style type="text/css">
    /*background-image:url('IMG_0396.JPG');*/
    h1{
        background-color:rgba(255,0,0,0.1);
    }
    .introduce{
        width: 1080px;
        border: 2px ridge red;
        margin:0 auto;
        padding:10px;
    }
    .lanshan{
        float:left;
    }
    .para{
        float:right;
        width:50%
    }
    h1,h2{
        text-align:center;
    }
    body{
        background-image:url('IMG_0396.JPG');
        background-repeat:repeat;
        background-attachment:fixed;
    }
</style>

</head>
<body>

    <div>
        <h1>CODINF COFFEE MENU<h1>
        <hr>
    </div>

    <div class="introduce" onClick="like(this)">
        <div>
            <img class="lanshan" src="./img/c3.jpg" height="200">
        </div>
        <div class="para">
            <h2 id="lanshan">蓝山咖啡</h2>
            <p>源自三地的咖啡豆,为周年纪念综合咖啡豆带来了特别的馥郁醇厚。</br>
            如今推出三种不同包装,让你用自己喜爱的方式体验这别具风味的一杯。</p>
        </div>
        <div style="clear:both;"></div>
    </div>
    <hr>

    <div class="introduce" onClick="like(this)">
        <div>
            <img class="lanshan" src="./img/c7.jpg" height="200">
        </div>
        <div class="para">
            <h2 id="natie">拿铁咖啡</h2>
            <p>每一款臻选咖啡豆,都有着自己的个性和故事。它因人因地因天气而有着别样的风味。<br>
            当你来到星巴克臻选门店,这场相遇才刚开始。和我们的黑围裙大师一起,用不同煮制方式,
            走进原产地的风情中。</p >
        </div>

        <div style="clear:both;"></div>

    </div>
    <hr>

     <div class="introduce" onClick="like(this)">
        <div>
            <img class="lanshan" src="./img/c8.jpg" height="200">
        </div>
        <div class="para">
            <h2 id="yishi">意式咖啡</h2>
            <p>作为在中国上市的第一款单一产地系列咖啡,东帝汶塔塔迈劳咖啡豆将当地的风味浓缩其中,<br>
            一起来星巴克门店,感受它那平衡的草本风味吧。</p >
        </div>
        <div style="clear:both;"></div>

    </div>
    <hr>

    <div class="introduce" onClick="like(this)">
        <div>
            <img class="lanshan" src="./img/c8.jpg" height="200" >
        </div>
        <div class="para">
            <h2 id="kabu">卡布基诺</h2>
            <p>源自三地的咖啡豆,为周年纪念综合咖啡豆带来了特别的馥郁醇厚。<br>
            如今推出三种不同包装,让你用自己喜爱的方式体验这别具风味的一杯。</p >
        </div>
        <div style="clear:both;">

        </div>
    </div>
    <hr>

    <div class="introduce" onClick="like(this)">
        <div>
            <img class="lanshan" src="./img/c5.jpg" height="200">
        </div>
        <div class="para">
            <h2 id="moka">摩卡咖啡</h2>
            <p>源自三地的咖啡豆,为周年纪念综合咖啡豆带来了特别的馥郁醇厚。<br>
            如今推出三种不同包装,让你用自己喜爱的方式体验这别具风味的一杯。</p >
        </div>
        <div style="clear:both;">

        </div>
    </div>
    <hr> 

    <script type="text/javascript">
        function loodAll(){
            var item = document.getElementsByClassName("introduce");
            for(var i=0;i<item.length;i++){
                    item[i].style.setProperty("background-image","none");
                }

                if(localStorage.length>0){
                    for(var i=0;i<localStorage.length;i++){
                        var id = localStorage.key(i);
                        document.getElementById(id).parentNode.parentNode.style.setProperty("background-image","url('big_head.jpg')");
                }
            }
        }
        function like(obj){
            var id = obj.childNodes[3].childNodes[1].id;
            var name = obj.childNodes[3].childNodes[1].innerHTML;
            for(var i=0;i<localStorage.length;i++){
                if(localStorage.key(i)==id){
                    localStorage.removeItem(id);
                    console.log(localStorage);
                    loodAll();
                    return;
                }
            }
            localStorage.setItem(id,name);
            loodAll();
            console.log(localStorage);
        }

    </script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值