0

リンクの作成tdlink image後処理とクローン作成が必要td:nth-child(2)a.link_topic_title

このスクリプトを作成しましたが、リンクは最初の行のリンクのみを複製します

$(document).ready(function () {
    $('#preview_active').change(function () {
        if ($(this).is(':checked')) {
            var url_thread = $('.link_topic_title').attr("href");
            var url_tooltip = "http://example.com" + url_thread
            $(".zebra thead tr th:first-child").attr('colspan', 4);
            $('.zebra tbody tr td:nth-child(2)').after('<td class="span1 icon"><a href="' + url_thread + '"><img src="http://icons.iconarchive.com/icons/visualpharm/must-have/256/Preview-icon.png" height="30px" width="25px" rel="tooltip" data-original-title="' + url_tooltip + '"/></a></td>');
            $('.zebra tbody tr td:nth-child(3) a img[rel=tooltip]').tooltip();
        } else {
            $(".zebra thead tr th:first-child").attr('colspan', 3);
            $('.zebra tbody tr td:nth-child(3)').remove();
        }
    });
});

jsfiddle : http://jsfiddle.net/5Vpra/2/

列のリスト リンクを別の列に複製する (td を作成する) にはどうすればよいですか?

アップデート

それぞれを使用してみましたが、すべてのリンクを取得できましたが、各 td に正常に複製されませんでした。

$(document).ready(function () {
    $('#preview_active').change(function () {
        if ($(this).is(':checked')) {

            classes = {};
               $('.link_topic_title').each(function() {
               $($(this).attr("href").split(' ')).each(function() { 
               if (this !== '') {
                 classes[this] = this;
                }    
                });
               });

            tds = '';
            $(".zebra thead tr th:first-child").attr('colspan', 4);
            $('.zebra tbody tr td:nth-child(2)').after('<td class="span1 icon"></td>');

            for (class_name in classes) {
             var url_tooltip = "http://example.com" + class_name
             tds += $('.zebra tbody tr td:nth-child(3)').append('<a href="' + class_name + '"><img src="http://icons.iconarchive.com/icons/visualpharm/must-have/256/Preview-icon.png" height="30px" width="25px" rel="tooltip" data-original-title="' + url_tooltip + '"/></a>');
                 $('.zebra tbody tr td:nth-child(3) a img[rel=tooltip]').tooltip();
          };
        } else {
            $(".zebra thead tr th:first-child").attr('colspan', 3);
            $('.zebra tbody tr td:nth-child(3)').remove();
        }
    });
});

jsfiddle : http://jsfiddle.net/5Vpra/3/

4

2 に答える 2

0
var url_thread = $('.link_topic_title').attr("href");

この行は、最初に見つかった .link_topic_title 要素から attr href を取得しています。そのため、作成したすべてのリンクの URL は同じです。リンクを追加するたびに自分がどの行にいるのかを知るために、for ループが必要だと思います。しかし、私は専門家ではなく、これを行うためのよりスムーズな方法があるかもしれません.

于 2013-07-22T10:20:33.270 に答える