0

私はここで特別な「問題」を抱えています。クライアントからのリクエストに対応するには、次のことを行う必要があります。ページ上のすべてのテーブルを実行します。各テーブルについて、正確に 2 つの TD があるかどうかを確認します。そうであれば、「続きを読む」の実装を行う必要があります。

折りたたんで展開したい正確なdivを知っている別のページでこれを使用しました。

$(".more-block").each(function(){
    if ($(this).height() > adjustheight){
        id = this.id;
        id = id.split("_");
        $("#expand"+id[1]).toggle(function() {
                id = this.id;
                $(".more-block"+id).css('height', 'auto').css('overflow', 'visible');
                $('html, body').animate({scrollTop: $(document).height()}, 'slow');
                $("#"+id).attr('src',path+'/images/expand2.png');
                $(".frontpage_box").css('height', '');
            }, function() {
                id = this.id;
                $("#"+id).attr('src',path+'/images/expand.png');
                $(".more-block"+id).animate({height: adjustheight}, "slow", function(){
                    $(".more-block"+id).css('height', adjustheight).css('overflow', 'hidden');
                });         
        });
    };
});

$(".more-block").css('height', adjustheight).css('overflow', 'hidden');

何か案は?TD を実行すると、クラス "more-less" と "more-lessexpand1" (数値はインクリメント) を追加するだけで済みます。これは可能ですか?テーブルを実行する方法がわかりません.2つのTDが見つかった場合にのみこれを実行し、2番目のTDで最後のビットのみを実行します.

ああ、ちなみに...重要なのは、崩壊して展開する唯一の 2 番目の TD です。左のものは許可されていません。誰かが関心のある TD を見つけるのを手伝ってくれれば、この最後のビットを解決できるかもしれません。

助けてください

4

2 に答える 2

1
$('table').filter(function(
    return $('td', this).length==2;
)).find('td').last().addClass('more-less more-lessexpand1');
于 2012-07-23T21:57:42.793 に答える
0

「誰かが関心のある TD を見つけるのを手伝ってくれれば、この最後のビットを解決できるかもしれません。」

ネストされたテーブルがないと仮定すると、次のようなものが目的のテーブルを見つけます。

$("table").each(function() {
   var $tds = $(this).find("td");
   if ($tds.length != 2)
       return;
   // this is a table with exactly two cells, so do something
   // $tds.eq(0) will reference first td;
   // $tds.eq(1) will reference second td;
   // So to add the classes to the second cell...
   $tds.eq(1).addClass("more-less more-lessexpand1");
});
于 2012-07-23T21:54:37.830 に答える