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;
}