博主信息
博文 25
粉丝 0
评论 0
访问量 23044
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
122作业点击商品选中效果
℃级的博客
原创
1046人浏览过

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<title>购物单</title>
	<meta charset="utf-8">
	<link rel="icon" type="image/x-icon" href="images/2.png">
	<script src="/122/jquery-2.1.4.min.js"></script>
	<style type="text/css">
        *{margin:0 auto;padding:0;}
        .top{width:402px;height:35px;background:rgba(255,0,0,0.5);text-align:center;line-height:35px;color:#fff;margin-top:50px;}
        .main{width:400px;height:400px;border:1px solid red;}
        p{width:400px;height:27px;margin-top:10px;}
        b{width:60px;height:25px;color:#838383;font-size:13px;text-align:center;line-height:29px;margin-left:10px;margin-top:5px;float:left;}
        span{width:70px;height:25px;border:1px solid #ccc;color:#838383;font-size:12px;margin-left:30px;text-align:center;float:left;line-height:25px;margin-top:5px;}
        span:hover{cursor:pointer;}
        button{width:100px;height:35px;background:rgba(255,0,0,0.5);text-align:center;line-height:35px;color:#fff;}
        .select{width:68px;height:23;border:1px solid rgba(255,0,0,0.5);text-align:center;line-height:23px;}
	</style>
</head>
<body>
<div class="top">天猫自选购物车</div>
<div class="main">
<p class="item" name="version">
<b class="notice">版本</b>
<span>ONE A001</span>
<span>ONE A002</span>
<span>ONE A003</span>
</p>
<p class="item" name="color">
<b class="notice">机身颜色</b>
<span>白色</span>
<span>黑色</span>
<span>金色</span>
</p>
<p class="item" name="type">
<b class="notice">套餐类型</b>
<span>标配</span>
<span>套餐一</span>
<span>套餐二</span>
</p>
<p class="item" name="ram">
<b class="notice">运行内存</b>
<span>2GB</span>
<span>3GB</span>
<span>4GB</span>
</p>
<p class="item" name="rom">
<b class="notice">机车内存</b>
<span>16GB</span>
<span>32GB</span>
<span>64GB</span>
</p>
<p class="item" name="location">
<b class="notice">产地</b>
<span>中国大陆</span>
<span>港澳台</span>
</p>
<p class="item" name="price">
<b class="notice">价格</b>
<span>999抢购</span>
</p>
<p class="item1" name="num">
<b class="notice">数量</b>
<input type="number" value="1" style="width:40px;height:25px;">
</p>
<p style="margin-top:20px;margin-left:80px;">
<button name="but1" id="sub1">加入购物车</button>
</p>
</div>
<script>
$(function(){
     $('span').click(function(){
     	if($(this).hasClass('select')){
              $(this).removeClass('select');
     	}else{
             $(this).addClass('select').siblings('span').removeClass('select');
     	}
     })
     $('#sub1').click(function(){
           let form={}
           let flag=true
           $('.item').each(function(){
                 if($(this).children('span.select').length!=1){
                  flag=false 
                      alert('未选中--'+$(this).children('.notice').html())           
                  }else{

                 let  key=$(this).attr('name')
                  let value=$(this).children('span.select').html()
                  form[key]=value
               }
      
      })
            if($('.item1 input').value<=0){
                   alert('请选择***数量!')
                   flag=false
               }else{
                   form['num']=$('.item1 input').value
                   flag=true
               }
               if(flag){
               	console.log(form)
               	alert('你可以加入购物车了')
               }
     })
    
     
     
})
</script>
</body>

</html>

运行实例 »

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

0..bmp1.bmp







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

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

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