标签:
效果如下:
要开模板文件 goods.dwt 把选择尺码跟颜色的代码替换成如下,(不同模板代码可能不一样,对照去替换)
<!-- {foreach from=$spec.values item=value key=key} --> <a {if $key eq 0}class="cattsel"{/if} onclick="changeAtt(this,{$value.id},{$goods.goods_id})" 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} -->
在要显视库存的地方放置以下代码
<font style=" color:#CCCCCC;">(库存:<font id="shows_number">{$goods.goods_number} {$goods.measure_unit}</font>)</font>
最后在JS代码里面添加以下JS 代码
function changeAtt(t,a,goods_id) { 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"; var formBuy = document.forms[‘ECS_FORMBUY‘]; spec_arr = getSelectedAttributes(formBuy); Ajax.call(‘goods.php?act=get_products_info‘, ‘id=‘ + spec_arr+ ‘&goods_id=‘ + goods_id, shows_number, ‘GET‘, ‘JSON‘); changePrice(); } function shows_number(result) { if(result.product_number !=undefined) { $(‘shows_number‘).innerHTML = result.product_number+‘件‘; } else { $(‘shows_number‘).innerHTML = ‘未设置‘ } }
再打开程序文件 goods.php 在70行左右添加代码
if (!empty($_REQUEST[‘act‘]) && $_REQUEST[‘act‘] == ‘get_products_info‘) { include(‘includes/cls_json.php‘); $json = new JSON; // $res = array(‘err_msg‘ => ‘‘, ‘result‘ => ‘‘, ‘qty‘ => 1); $spce_id = $_GET[‘id‘]; $goods_id = $_GET[‘goods_id‘]; $row = get_products_info($goods_id,explode(",",$spce_id)); //$res = array(‘err_msg‘=>$goods_id,‘id‘=>$spce_id); die($json->encode($row)); }
现在就可以了,到后台清除下缓存试试。
如果想实现选择打勾的效果,参阅这篇 http://www.cnblogs.com/wangblognet/archive/2013/04/11/3014112.html
标签:
原文地址:http://www.cnblogs.com/wangblognet/p/4514026.html