jquery在任何未打开的文本之前直接在每个结束标记之后追加

时间:2014-09-20 17:44:00

标签: jquery

我无法在关闭每个玩家名称的标签后直接显示我的图片链接

以下是脚本的片段

if (shouldAddPopupIcon()) {
    var bodyId = $('body').attr('id');

    if (bodyId === 'body_options_02') {
        $.each($('a[class^="position_"], td.cbsPlayerName a ,td.playertd a'), function (index, value) {
            var id = getPlayerIdFromHref($(this).attr('href'));
            _playerPopupIds.push(id);
        });

        _playerPopupIds = getUniqueArray(_playerPopupIds);

        $.ajax({
            type: 'GET',
            url: getPlayerProfileApiUrl()
        }).done(function (data) {

            $.each($('a[class^="position_"], td.cbsPlayerName a, td.playertd a'), function (index, value) {
                try {
                    if(!$(this).nextAll('a').hasClass('playerPopupNewsIcon'))
                        {                               
                            var id = getPlayerIdFromHref($(this).attr('href'));

                            var profile = $.grep(data.playerProfiles.playerProfile, function (p) {
                                return p.id === id;
                            })[0];

                            var newsIcon = getNewsIconType(profile);
                            var playerName = $(this).text();
                            var link = getPlayerPopupLink(id, playerName, newsIcon);

                            $(this).parent().append(link);

                            if (_settings.playerClickShowsPopup) 
                            {
                                $(this).unbind().click(function () 
                                {
                                    renderPopup(id, playerName);
                                    return false;
                                });
                            }
                        }
                    } 
                catch (err) { }
            });
        });
    } else {
        $.each($('td.player'), function (index, value) {
            var id = getPlayerIdFromHref($(this).children().first().attr('href'));
            _playerPopupIds.push(id);
        });

        _playerPopupIds = getUniqueArray(_playerPopupIds);

        $.ajax({
            type: 'GET',
            url: getPlayerProfileApiUrl()
        }).done(function (data) {
            $.each($('td.player'), function (index, value) {
                try {
                    var id = getPlayerIdFromHref($(this).children().first().attr('href'));

                    var profile = $.grep(data.playerProfiles.playerProfile, function (p) {
                        return p.id === id;
                    })[0];

                    var newsIcon = getNewsIconType(profile);
                    var playerName = $(this).children().first().text();
                    var link = getPlayerPopupLink(id, playerName, newsIcon);

                    $(this).append(link);

                    if (_settings.playerClickShowsPopup) {
                        $(this).unbind().click(function () {
                            renderPopup(id, playerName);
                            return false;
                        });
                    }
                } catch (err) { }
            });
        });
    }
}

}

这是脚本运行前的HTML

<p>Franchise 1 were helped out by a point effort from 
<a href="#" class="position_wr">PLAYER NAME 1</a>
, who  snuck past the New Orleans Saints defense for 44 receiving yards and 1 receiving TD.  They also got help from a point effort from 
<a href="#" class="position_pk">PLAYER NAME 2</a>
, who  beat the   defense for  field goals made.
</p>

接下来,你会注意到脚本在所有文本之后放置了新的链接img

    <p>Franchise 1 were helped out by a point effort from 
    <a href="#" class="position_wr">PLAYER NAME 1</a>
    , who  snuck past the New Orleans Saints defense for 44 receiving yards and 1 receiving TD.  They also got help from a point effort from 
    <a href="#" class="position_pk">PLAYER NAME 2</a>
    , who  beat the   defense for  field goals made.
<a title="news" href="#"><img class="playerPopupNewsIcon" alt="news" src="#"></a>
<a title="news" href="#"><img class="playerPopupNewsIcon" alt="news" src="#"></a>
    </p>

我希望新的图片链接直接放在每个a.position结束标记之后,以及展开的文本之前。我无法访问HTML以更好地标记它。 希望看起来像这样

<p>Franchise 1 were helped out by a point effort from 
<a href="#" class="position_wr">PLAYER NAME 1</a><a title="news" href="#"><img class="playerPopupNewsIcon" alt="news" src="#"></a>
, who  snuck past the New Orleans Saints defense for 44 receiving yards and 1 receiving TD.  They also got help from a point effort from 
<a href="#" class="position_pk">PLAYER NAME 2</a><a title="news" href="#"><img class="playerPopupNewsIcon" alt="news" src="#"></a>
, who  beat the   defense for  field goals made.
</p>

0 个答案:

没有答案