如何使用 js 将 json 响应插入 <a>xxxxx</a>
How do you use js to insert json response into <a>xxxx</a>
我正在尝试在我的 tumblr 帖子中实现一个"最新"的小部件。到目前为止,我已经能够从这篇文章(http://stackoverflow.com/questions/5617378/how-to-display-a-link-to-my-latest-tumblr-post-using-javascript)中使用 json 获取前 5 个最新帖子。我想知道如何将{title}
插入 xxx 中,以便链接显示最近帖子的标题。
我想我需要使用 .append 或 .html,但我不确定该怎么做。 有人可以帮我吗?
贾夫文:
$.getJSON('http://brianjsmith.tumblr.com/api/read/json?callback=?',
function(response) {
$('#myLink').attr('href',response.posts[0].title);
});
.html:
<a id=#myLink>Most recent post {title}</a>
$('#myLink').attr('href',response.posts[0].url).text(response.posts[0].title);
更新:检查响应后,没有title
属性,只有regular-title
。
$('#myLink').attr('href',response.posts[0].url).text(response.posts[0]['regular-title']);
$("#myLink").html('Most recent post' + response.posts[0].title)
相关文章:
- 将样式表插入iframe
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 如何动态插入jquery代码
- 动态插入的表:JQuery未检测到最后一行
- 使用JavaScript动态插入DIV的成本有多高
- 带有填充属性的SVG矩形显示在包含元素的上方插入框阴影
- 将对象动态插入到现有对象中
- 将数组中的值插入到表中
- 在 Java 中的 JavaScript 函数中插入 Wicket 值
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 数据绑定:'系统Char'不包含名为'xxxxx'
- 使用PHP插入HTML在JavaScript上不起作用
- javascript:将数据库中的数据插入到html5文本字段中
- 从数据库中获取数据并插入JavaScript变量
- 如何使用innerHtml正确插入html
- AngularJS指令,在元素后插入HTML
- 当用户按下回车键时,自动在text区域/text中插入消息
- 如何使用JS禁用表行,并在MYSQL中插入所选选项
- 将文本插入光标所在的文本区域
- 如何使用 js 将 json 响应插入 xxxxx