ecshop商品属性仿淘宝选择功能

二话不说直接上效果图:

enter image description here

实现原理:

1:css控制本来要显示的radio为一小矩形.

2:当点击此小矩形时,js使此radio选中,同时改变此小矩形的外观样式.

涉及的修改文件,请做好备份(default模板为例)

/themes/default/style.css

/themes/default/goods.dwt

注:此路径为待修改模板路径(default修改为你的模板文件夹名称).

一:控制样式

1.打开/themes/default/images/

添加test.gif图片show_mop.gif

2.打开/themes/default/style.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:#ED0036 2px solid; margin: -1px; margin-left:4px;margin-top:5px;}
.catt a:focus {outline-style:none;}
.catt .cattsel {border:#ED0036 2px solid; margin: -1px;background: url("images/test.gif") no-repeat bottom right; margin-left:4px;margin-top:5px;}
.catt .cattsel a:hover {border: #ED0036 2px solid;margin:-1px;background: url("images/test.gif") no-repeat bottom right;}

3.打开/themes/default/goods.dwt

注:以下修改以原版ecshop2.7.0版本default(模板名称)为基准 未修改前第347-351行

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

二:增加js控制样式与选中行为 在页面内找到

这样的东西,在其后面添加一个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();
}

 

转载自:http://www.9958.pw/post/ecshop_attr_select

posted @ 2016-03-06 12:10  ldl_xz  阅读(301)  评论(0编辑  收藏  举报