0
私はコメントのリストを表示/非表示にするためにトグルjQueryスクリプト(下記参照)を使用しようとしています。スクリプトは無限のスクロール機能を実装した後、前の投稿の "showtext"を繰り返します(すなわち、無限のスクロールを持つ次の投稿の3つの読み込みの後に "(show)"の3つのコピーがあります) 。無限のスクロールでjqueryトグルを使用する
私はこれがスクリプトの「追加」行のためであることを認識していますが、これをコメントアウトしてclass = "toggleLink"のページにリンクを張ると、コンテンツは切り替わりません。リンクのテキストはhideTextに変わるので、なぜコンテンツが表示されないのか不思議です。助けてくれてありがとう!
$(document).ready(function() {
// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='show';
var hideText='hide';
// initialise the visibility check
var is_visible = false;
// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggle').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');
// hide all of the elements with a class of 'toggle'
$('.toggle').hide();
// capture clicks on the toggle links
$('a.toggleLink').click(function() {
// switch visibility
is_visible = !is_visible;
// change the link depending on whether the element is shown or hidden
$(this).html((!is_visible) ? showText : hideText);
// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.toggle').toggle('slow');
// return false so any link destination is not followed
return false;
});
});
あなたのjQueryバージョンによっては、あなたが追加したり削除した要素にバインドする際に便利です(http://api.jquery.com/live/)。 DOM。 –