jQuery的追加到的foreach DIV
题
我想使用jQuery来创建一个动态的标签云,我希望它从页面拉关键字,然后将它们吐出的一个div,但我不知道如何去了解它 - 我知道我怎么能做到这一点,如果它是PHP,但只是没有在jQuery的那么好。
我已经建立了我的变量 “关键字”
var keywords = jQuery("meta[name=keywords]").attr("content");
现在我怎么去这样做一个foreach为它追加格“tagCloud”是这样的:
<div class="tagCloud" id="tagCloud">
Keyword 1 \n
Keyword 2 \n
Keyword 3 \n
</div>
等等..如果有人可以帮助我,那简直是太棒了:)
解决方案
假设要云关键字是链接(锚):
$($('meta[name="keywords"]').attr('content').split(',')).each(function(i, el) {
$('#tagCloud').append($('<a>').attr('href','#').text(el));
});
其他提示
我愿意做这样的:
var all = "";
jQuery("meta[name=keywords]").each(function(){
all += jQuery(this).attr("content") + "\n";
});
jQuery("#tagCloud").html(all);
不隶属于 StackOverflow