【发布时间】:2016-10-09 03:59:31
【问题描述】:
为“每个主题标签”创建一个 href 链接。
但是,下面的代码仅为 JSON 文件中的“最后一个主题标签”创建 href 链接。
遍历 JSON 数组
rows
[ ], [ ],
[
content: "With the #a b, c at tonight's ..",
hashtags: [
"a",
"b",
"c"
],
$.ajax('https://rest.xyz.com/..', {
type: 'GET',
dataType: 'json',
success: function( data ) {
for(i in data.rows[3].hashtags){
content3 = data.rows[3].content.replace(
new RegExp('#'+data.rows[3].hashtags[i], 'g'),
'<a href="https://x.com/hashtags/'+
data.rows[3].hashtags[i]+'"'+
'target="_blank">'+'#'+data.rows[3].hashtags[i]+'</a>'
)
}
【问题讨论】:
标签: javascript arrays json ajax replace