これは、基本的なJavaScriptに簡単に変換できますが、小さなjQueryで構築された機能する関数です。
jQuery:
<script>
$(function(){
$('.tags').each(function(){
var obj=$(this),tags=obj.text().split(','),i=0,len=tags.length;
if(obj.text()) {
for(i;i<len;i++) {
var tag=tags[i].replace(/(^\s*)|(\s*$)/g,'');
tags[i]='<a href="http://oursite.com/search?query='+encodeURIComponent(tag)+'">'+tag+'</a>';
}
obj.html(tags.join(', '));
}
});
});
</script>
HTML:
<div class="tags">abp, accredited building practitioners, calendar of events, upcoming events</div>
<div class="tags">test, another test, some more testing, etc</div>
<div class="tags">the, code, needed, to, be , in, an, each(), loop</div>
<div class="tags"></div>
<div class="tags">random, words, that, show, work, hopefully</div>
<div class="tags">the, return, false, was, causing, problems</div>
<div class="tags"></div>