根據(jù)模板不同,大家參考著修改模板,為避免出錯(cuò),修改時(shí)請務(wù)必備份模板以涉及到被修改的文件!
首先演示下效果:

實(shí)現(xiàn)原理:
1:css控制本來要顯示的radio為一小矩形.
2:當(dāng)點(diǎn)擊此小矩形時(shí),js使此radio選中,同時(shí)改變此小矩形的外觀樣式.
涉及的修改文件,請做好備份(default模板為例)
/themes/default/style.css
/themes/default/goods.dwt
注:此路徑為待修改模板路徑(default修改為你的模板文件夾名稱).
一:控制樣式
1.打開/themes/default/images/
添加圖片test.gif.
2.打開/themes/default/style.css
最下面添加:
/--------------顏色選擇器CSS添加-------------/.catt{width:100%;height:auto;overflow:hidden;padding-bottom:5px;}.catt a{border:#c8c9cd1pxsolid;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:#ED00362pxsolid;margin:-1px;margin-left:4px;margin-top:5px;}.catt a:focus {outline-style:none;}.catt.cattsel{border:#ED00362pxsolid;margin:-1px;background:url("images/test.gif")no-repeatbottomright;margin-left:4px;margin-top:5px;}.catt.cattsel a:hover {border:#ED00362pxsolid;margin:-1px;background:url("images/test.gif")no-repeatbottomright;}
3.打開/themes/default/goods.dwt
注:以下修改以原版ecshop2.7.2版本default(模板名稱)為基準(zhǔn)
未修改前第347-351行
<label for="spec_value_{value.id}" onclick="changePrice()" name="spec_{
value.id}" /> {
value.price gt 0}{
value.price lt 0}{
value.format_price|abs}] </label>
修改為:
<div class="catt"> <a {if value.id}">{
value.id}" type="radio" name="spec_{
value.id}" {if $key eq 0}checked{/if} /></a> </div>
此處為是了將radio換成淘寶上那種小矩形樣式顯示在頁面.
二:增加js控制樣式與選中行為
在頁面內(nèi)找到
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();}
說明:
1.以上修改會(huì)將商品屬性部分所有radio修改.
2.由于用戶goods.dwt可能都被修改過,用戶請根據(jù)自己的實(shí)際情況修改.
用到一個(gè)圖片素材,url(“images/test.gif”)
