因为公司现在在增加服装类货源,所以经常涉及到一些模板的修改问题,比如商品的颜色尺寸等属性选择,ecshop默认的是下拉菜单 和点选两种形式,样式特别不耐看,淘宝选择那种方形的框选已经是主流,像shopex的属性选择就是仿淘宝那种框选特别美观!下面分享一下ecshop修 改成框选的经验,根据模板不同,大家参考着修改模板,为避免出错,修改时请务必备份模板以涉及到被修改的文件!
一:控制样式 2.打开/themes/default/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:#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}">{$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控制样式与选中行为 function changePrice() 在其上面增加 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(); } 说明: 用到一个图片素材,url(“images/test.gif”) |
|