您的位置:首页 > 运维架构

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

2017-04-09 22:31 344 查看
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>   ';
}
}
catch (e) { alert(e); }
}
},
'json');
}
}
catch (e) { alert(e); }
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html ecshop 二次开发