Javascript 在标题上显示文章标题
每次单击帖子链接时,我都希望帖子的标题出现在标题页上。参见屏幕截图 如前所述,我希望“虔诚的信息”被帖子标题所取代 HTML代码:Javascript 在标题上显示文章标题,javascript,jquery,ajax,Javascript,Jquery,Ajax,每次单击帖子链接时,我都希望帖子的标题出现在标题页上。参见屏幕截图 如前所述,我希望“虔诚的信息”被帖子标题所取代 HTML代码: <div id="devotionpost" data-role="page"> <div data-role="header" data-position="fixed" data-theme="a"> <h1>Devotional Message</h1>
<div id="devotionpost" data-role="page">
<div data-role="header" data-position="fixed" data-theme="a">
<h1>Devotional Message</h1>
<a href="#devotion" data-icon="back" data-iconpos="notext">Devotion</a>
</div><!-- header-->
<div data-role="content">
<div id="mypost"> </div>
</div><!-- content -->
</div><!-- page -->
虔诚的信息
JS代码:
function showPost(id) {
$.getJSON('http://howtodeployit.com/?json=get_post&post_id=' + id + '&callback=?', function(data) {
var output='';
output += '<h3>' + data.post.title + '</h3>';
output += data.post.content;
$('#mypost').html(output);
});
功能显示柱(id){
$.getJSON('http://howtodeployit.com/?json=get_post&post_id=“+id+”&回调=?”,函数(数据){
var输出=“”;
输出+=''+data.post.title+'';
输出+=data.post.content;
$('#mypost').html(输出);
});
功能显示柱(id){
$(“#奉献岗位h1”).html(“”;//清空上一个标题
$.getJSON('http://howtodeployit.com/?json=get_post&post_id=“+id+”&回调=?”,函数(数据){
var输出=“”;
输出+=''+data.post.title+'';
输出+=data.post.content;
$('#mypost').html(输出);
$(“#奉献岗位h1”).html(data.post.title);//由此“奉献信息”替换为岗位标题。。
});
Brilliant这很有效,但有一个小问题。每次我返回并单击另一篇文章,当新文章准备加载时,以前访问的文章的标题仍然显示,只有在新文章最终加载时才会被替换。我如何清空标题位?啊……你真是个聪明人。我这么做了,但放错了位置e、 谢谢你今天的帮助
function showPost(id) {
$("#devotionpost h1").html("");// to empty previous title
$.getJSON('http://howtodeployit.com/?json=get_post&post_id=' + id + '&callback=?', function(data) {
var output='';
output += '<h3>' + data.post.title + '</h3>';
output += data.post.content;
$('#mypost').html(output);
$("#devotionpost h1").html(data.post.title);// by this 'Devotional Message' replaced by the Post Title..
});