2012-01-06 14 views
0

ブログに2つのボタンを作成して、ユーザーが次のまたは後ろのトラフの投稿に行くことができます。投稿のタイトルを表示するのは面白いと思う。それはので、私はURLのように私は.LOADでそれらを使用してその投稿のタイトルをターゲットにすることができますをキャッチするために変数を使用しようとしているのBlogSpotのブログだ:jQueryで変数を含む.loadを使用する

$(function(){ 
    var getlink = $("a.blog-pager-newer-link").attr("href"); 
    var gettitle = $('.entry').load(getlink+ "#this-post-title"); //this part won't work! 
    $("<div id='next-title'>"+gettitle+"</div>").appendTo("a.blog-pager-newer-link"); 
}); 

答えて

0

あなたは、一般的なロジックの問題を持っています。

$(function(){ 
     // set getlink equal to the value of the href attribute of the link 
     var getlink = $("a.blog-pager-newer-link").attr("href"); 
     // set gettitle equal to the element with a class of entry 
     var gettitle = $('.entry').load(getlink+ "#this-post-title"); //this part won't work! 
     // create a new div that contains the toString of the gettitle object([object Object]) 
     $("<div id='next-title'>"+gettitle+"</div>").appendTo("a.blog-pager-newer-link"); 
}); 

あなたが実際にやりたいことは、URLの内容をリンクに読み込むことです。

$(function(){ 
     // set getlink equal to the value of the href attribute of the link 
     var getlink = $("a.blog-pager-newer-link").attr("href"); 
     // load contents of page at link into link 
     $("a.blog-pager-newer-link").load(getlink + " #this-post-title"); // the space is important too 
}); 
関連する問題