Ecshop模板开发(十四):商品详情页显示与添加标签

来源:互联网 发布:网络解锁助手1.0.9 编辑:程序博客网 时间:2024/05/16 08:13

1、html

{if $tags}                <h2>商品标签</h2>                #show the tags                <p>                    {foreach from=$tags item=tag}                        <a href="search.php?keywords={$tag.tag_words|escape:url}">{$tag.tag_words|escape:html}[{$tag.tag_count}]</a>                    {/foreach}                </p>        #add the tags                <form action="javascript:;" name="tagForm" id="tagForm" onsubmit="return submitTag(this)">                    <input type="text" name="tag" id="tag">                    <input type="submit" value="添加">                    <input type="hidden" name="goods_id" value="{$goods.goods_id}">                </form>                <p id="ECS_TAGS"></p>            {/if}

2、js

    function submitTag() {        try        {            var tag = $('input[name=tag]').val();            var idx = $('input[name=goods_id]').val();            if (tag.length > 0 && parseInt(idx) > 0)            {                $.post(                        'user.php?act=add_tag',                        {'id':idx,'tag':tag},                        function (result) {                            var div = document.getElementById('ECS_TAGS');                            if (result.error > 0)                            {                                alert(result.message);                            }                            else                            {                                try                                {                                    div.innerHTML = '';                                    var tags = result.content;                                    for (i = 0; i < tags.length; i++)                                    {                                        div.innerHTML += '<a href="search.php?keywords='+tags[i].word+'" style="color:#006ace; text-decoration:none; margin-right:5px;">' +tags[i].word + '[' + tags[i].count + ']<\/a>&nbsp;&nbsp; ';                                    }                                }                                catch (e) { alert(e); }                            }                        },                        'json');            }        }        catch (e) { alert(e); }        return false;    }
1 0
原创粉丝点击