• ecshop商品颜色尺寸仿淘宝选择功能教程


    效果演视如图:

    修改方法:

    注:此功能与具体的模板相关,无法写出通用教程.因为,此帖子以讲原理为主.

    请大家运用时举一反三,不要生搬硬套代码.
    也因为同样的原因,此篇帖子不回帖因个人安装导致的问题,只解决确实属于代码漏洞的问题.

    原理:
    1:css控制本来要显示的radio为一小矩形.
    2:当点击此小矩形时,js使此radio选中,同时改变此小矩形的外观样式.

    牵涉到的修改文件(default模板为例)
    /themes/default/style.css
    /themes/default/goods.dwt
    注:此路径待修改模板路径.



    修改步骤:
    一:控制样式


    1.打开/themes/ecshop/images
    加添图片test.gif.



    2.打开/themes/ecshop/style.css
    最下面添加:

    /*--------------颜色选择器CSS添加-------------*/
    
    .catt{width:100%;height:auto;overflow:hidden;padding-bottom:5px;}
    
    .catt a{border: #c8c9cd 1px solid;  text-align: center; background-color: #fff; margin-left:5px;margin-top:6px;padding-left: 10px;padding-right: 10px;display: block; white-space: nowrap; color: #000; text-decoration: none;float:left;}
    
    .catt a:hover {border:#ff6701 2px solid; margin: -1px; margin-left:4px;margin-top:5px;}
    
    .catt a:focus {outline-style:none;}
    
    .catt .cattsel {border:#ff6701 2px solid; margin: -1px;background: url("images/test.gif") no-repeat bottom right; margin-left:4px;margin-top:5px;}
    
    .catt .cattsel a:hover {border: #ff6701 2px solid;margin:-1px;background: url("images/test.gif") no-repeat bottom right;}

    3.打开/themes/ecshop/goods.dwt 查找下面代码

    注:以下修改以原版ecshop2.7.0版本default(模板名称)为基准

    未修改前第347-351行

    <!-- {foreach from=$spec.values item=value key=key} -->
    
    <label for="spec_value_{$value.id}">
    
    <input type="radio" name="spec_{$spec_key}" value="{$value.id}" id="spec_value_{$value.id}" {if $key eq 0}checked{/if} onclick="changePrice()" />
    
    {$value.label} [{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}] </label><br />
    
    <!-- {/foreach} -->


    修改为

    <div class="catt">
    
    <!-- {foreach from=$spec.values item=value key=key} -->
    
      <a {if $key eq 0}class="cattsel"{/if} onclick="changeAtt(this)" href="javascript:;" name="{$value.id}" title="[{if $value.price gt 0}{$lang.plus}{elseif $value.price lt 0}{$lang.minus}{/if} {$value.format_price|abs}]">{$value.label}<input style="display:none" id="spec_value_{$value.id}" type="radio" name="spec_{$spec_key}" value="{$value.id}" {if $key eq 0}checked{/if} /></a>
    
    <!-- {/foreach} -->
    
    </div>

    此处为是了将radio换成淘宝上那种小矩形样式显示在页面.



    二:增加js控制样式与选中行为
    在页面内找到<script>这样的东西,在其后面添加一个js函数

    function changeAtt(t) {
    t.lastChild.checked='checked';
    for (var i = 0; i<t.parentNode.childNodes.length;i++) {
            if (t.parentNode.childNodes[i].className == 'cattsel') {
                t.parentNode.childNodes[i].className = '';
            }
        }
    t.className = "cattsel";
    changePrice();
    }

    此处是为了控制 选择页面上的颜色 同时也选中了对应的隐藏input 从而来更改商品属性.如:价钱...等.
    如果是用户修改过的goods.dwt可搜索:function
    changePrice()在其上面添加.


    说明:
    1.以上修改会将商品属性部分所有radio修改.
    2.由于用户goods.dwt可能都被修改过,用户请根据自己的实际情况修改.
    3:对于颜色选择功能,这是目前本论坛上最简单的实现方法.

    文中所用附件


    test.gif如下:    (右键另存为就可以了。)

  • 相关阅读:
    Java之基于注解的Excel导出
    从box-sizing:border-box属性入手,来了解盒模型
    提交代码出现 Push to origin/master was rejected 错误解决方法
    Mysql锁表解锁
    httpclient工具使用(org.apache.httpcomponents.httpclient)
    Jackson总结:常用注解、整合spring、自定义JsonSerializer
    Linux创建目录和文件的默认权限设置(umask命令)
    Apache Phoenix的子查询
    Apache Phoenix的Join操作和优化
    Apache Phoenix的Array类型
  • 原文地址:https://www.cnblogs.com/wangblognet/p/2811571.html
Copyright © 2020-2023  润新知