搜索
博主信息
博文 12
粉丝 0
评论 0
访问量 12704
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
商品选择滚动距离获取-2019年1月22日22时
兰岚的博客
原创
807人浏览过

实例

<!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>

运行实例 »

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


批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学