ajax を使用して投稿を更新するコードを作成しました。
$(function(){
$('#loadFeed').bind('click',function(){
$.getJSON('getData.php', function(json) {
var output="<ul id='feedsList'>";
for(var i=json.posts.length-1;i>=json.posts.length-31;i--){
output+="<li class='post'>";
output+="<div class='text'>"+json.posts[i].shortmsg+"</div>";
output+="</li>";
}
output+="</ul>"
$(output).appendTo('.posts');
});
});
});
私のhtmlコード:
<div data-role="content" class="ui-content" role="main">
<div class="posts"></div>
</div>
次に、各投稿をクリックすると、投稿が展開されて詳細なコンテンツが表示されます。どうすればよいですか? 私が書いたコードは次のとおりです。
$(function(){
$('.text').bind('click',function(){
$.getJSON('getData.php', function(json){
var thisID = this.id;
$(this).replaceWith("<div class='long_text'>"+json.posts[thisID].msg+"<div>");
});
});
});
しかし、それは何もしませんでした。
var thisID = this.id;
働いたかどうか。コードを少し変更しました。
$(function(){
$('.text').bind('click',function(){
alert("Hello!")
});
});
それでも何も起こりません!! 関数で .text が選択されているかどうか疑問に思いました。