在标题上显示帖子标题

时间:2013-10-14 07:26:22

标签: javascript jquery ajax

每次点击帖子链接时,我都希望帖子的标题出现在页眉页面上。请参见屏幕截图enter image description here

如图所示,我希望将'Devotional Message'替换为帖子标题......

HTML代码:

<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);
    }); 

1 个答案:

答案 0 :(得分:2)

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..

    });