我如何使用 java 脚本从新选项卡中的数组打开 link?

how do i open link from array in new tab using java script?

我在 javascript 数组中获取 RSS 提要并显示在 HTML 列表中。 但我希望当用户单击 link 时,它必须在新选项卡中打开。

//HTML

<ol class="list">
</ol>

//Java 脚本

<script>    


$(function() {
    getRssFeed("https://amirtariq69.blogspot.com/feeds/posts/default?alt=rss", mapFeed);

});


function getRssFeed(url, callback) {
    return feednami.loadGoogleFormat(encodeURI(url), callback);
}

function mapFeed(result) {
    if (result.error) {
      console.log(result.error)
  } else {
        createCarouselList(result.feed.entries.slice(0, 5));
        createFeedList(result.feed.entries.slice(0, 10));
  }
}


function createCarouselList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><h3><a href='"+ element.link +"'>"+ element.title +"</a></h3><p>"+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"</p><span class='carousel-footer'>"+ (index + 1) +" out of 5</span></li>");
    });

    $(".carousel").append(list);

}


// Edit this function please ...
function createFeedList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><a href='"+ element.link +"'>"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>");
    });
    $(".list").append(list);
    returnCarouselList();
}

    </script>

在我提到编辑功能的地方,任何人都可以将此列表添加到(在新标签页中打开)列表。

添加到a标签:

target="_blank"

已解决

function createFeedList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><a href='"+ element.link + "' target='_blank +'>"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>");
    });
    $(".list").append(list);
    returnCarouselList();
}
``````````````````````

尝试添加目标属性 target="_blank">,如下所示

<script>    


$(function() {
    getRssFeed("https://amirtariq69.blogspot.com/feeds/posts/default?alt=rss", mapFeed);

});


function getRssFeed(url, callback) {
    return feednami.loadGoogleFormat(encodeURI(url), callback);
}

function mapFeed(result) {
    if (result.error) {
      console.log(result.error)
  } else {
        createCarouselList(result.feed.entries.slice(0, 5));
        createFeedList(result.feed.entries.slice(0, 10));
  }
}


function createCarouselList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><h3><a href='"+ element.link +"target="_blank">"+ element.title +"</a></h3><p>"+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"</p><span class='carousel-footer'>"+ (index + 1) +" out of 5</span></li>");
    });

    $(".carousel").append(list);

}


// Edit this function please ...
function createFeedList(elements) {
    var list = [];
    $(elements).each(function(index, element) {
        list.push("<li><a href='"+ element.link +" target="_blank">"+ element.title + "&nbsp; ["+ new Date(element.publishedDate).toLocaleDateString("pt-BR") +"] "+"</a></li>");
    });
    $(".list").append(list);
    returnCarouselList();
}

    </script>