二話不說直接上效果圖:javascript
實現原理:css
1:css控制原本要顯示的radio爲一小矩形.java
2:當點擊此小矩形時,js使此radio選中,同時改變此小矩形的外觀樣式.函數
涉及的修改文件,請作好備份(default模板爲例)post
/themes/default/style.cssthis
/themes/default/goods.dwturl
注:此路徑爲待修改模板路徑(default修改成你的模板文件夾名稱).spa
一:控制樣式code
1.打開/themes/default/images/orm
添加test.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(); }