簡體   English   中英

如何使用Java腳本在新選項卡中打開數組中的鏈接?

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

我在JavaScript數組中獲取RSS feed,並顯示在HTML列表中。 但我希望當用戶單擊鏈接時,它必須在新選項卡中打開。

// 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>

在這里我提到編輯功能,任何人都可以將此列表添加到(在新標簽頁中打開)列表中。

添加到標簽:

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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM