Blogger Information
Blog 12
fans 0
comment 0
visits 10128
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
商品选择滚动距离获取-2019年1月22日22时
兰岚的博客
Original
632 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <style>
        *{margin:0;paading:0;}
        p{padding:6px 0 5px 0;text-align: center;}
        label{width:80px;font-weight: bold;font-size:12px;color:grey;display:inline-block;}
        button{width:100px;height:35px;border:1px solid #c40000;background-color:#c40000;color:white;margin:20px 100px;}
        span{width:80px;height:25px;font-size:12px;line-height: 25px;color:grey;border:1px solid lightgray;display:inline-block;}
        .select{border:2px solid #C40000;width: 78px;height: 23px;line-height: 23px;color: red;}
    </style>
</head>
<body>
    <form action="check.php" method="POST" style="width:380px;height:450px;border:1px solid #c40000;margin:0 auto;">
        <p style="background-color:#c40000;color:white;font-size:16px;">请选择信息后加入购物车</p>
        <p>
            <label>机型</label>
            <span>ONE A2001</span>
            <span>ONE A0001</span>
            <span>ONE A1001</span>            
        </p>
        <p>
                <label>机身颜色</label>
                <span>白色</span>
                <span>黑色</span>
                <span>金色</span>            
        </p>
        <p>
                <label>套餐类型</label>
                <span>标配</span>
                <span>套餐一</span>
                <span>套餐二</span>            
        </p>
        <p>
                <label>运行内存</label>
                <span>2GB</span>
                <span>3GB</span>
                <span>4GB</span>            
        </p>
        <p>
                <label>机身内存</label>
                <span>16GB</span>
                <span>32GB</span>
                <span>64GB</span>            
        </p>
        <p>
                <label>产地</label>
                <span>中国大陆</span>
                <span>港澳台</span>
                <label></label>
        </p>
        <p>
                <label>价格</label>
                <span>999元抢购</span>
                <label></label>
                <label></label>
        </p>     
        <p>
                <label for="sl">数量</label>
                <input type="number" style="width:80px;" name="sl"/>
                <label></label>
                <label></label>
        </p> 
        <button>加入购物车</button>   
    </form>
    <script>
        
        $(function() {
        $('span').click(function(){
            if($(this).hasClass('select')){     //注意c必须大写,必须引入jquery
                $(this).removeClass('select')
            }else{
                $(this).addClass('select').siblings('span').removeClass('select')
            }
        })
        $('button').click(function(){
            var arr1=$('form').find('.label')
            var arr2=$('form').find('.select')
            for (i=0;i<arr1.length;i++){
                console.log(arr1[i].val()+arr2[i].val())
            }
        })
        })
    </script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style>
*{margin:0 auto;padding:0;}
.content{width:100%;height:60px; background:rgba(160,3,162,0.1);line-height:60px;position:fixed;}
.contentc2{background-color: rgba(94, 4, 95, 0.4);}
form{width:500px;height:20px;}
input{width: 170px;height:20px;border-radius:20px 0px 0px 20px;padding-right:20px;}
button{width: 70px;height:25px;background-color: pink;border-radius:0px 20px 20px 0px;}
[placeholder]{}
.pic{width:1000px;height:500px;background: url(images/3.jpg);}
.box{width:1000px;height:1000px;}

</style>
</head>
<body>
<!-- 顶部导航 -->
<div class="content">
<form>
<input type="text" placeholder="# 请输入关键词 #">
<button>全网搜</button>
</form>
</div>
<!-- 轮播图 -->
<div class="pic"></div>
<!-- 页面详情 -->
<div class="box"></div>
<script>
$(function(){                            //注意写法function在括号内,function别拼错
$(window).scroll(function(){
if ($(window).scrollTop()>60){   //window).scrollTop()
$('.content').css('display','none')
}else{
$('.content').css('display','block')
}

if ($(window).scrollTop()>500){
$('.content').addClass('contentc2').css('display','block')//不加点号
}else{
$('.content').removeClass('contentc2')//为什么命名为content2不行,contentc2却可以?
}
})
})


</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post