2017-02-28 56 views
-1

我想編輯悉尼主題(wordpress)的滑塊按鈕,爲每個按鈕分別設置鏈接,並找到以下JQuery代碼。此代碼運行良好,但打開當前頁面中的鏈接。現在,我想編輯此代碼以打開新選項卡中的鏈接。我怎麼能這樣做?JQuery代碼打開新標籤中的鏈接

jQuery(function($) { 
 

 
    //Define the new buttons. Delete the lines you don't need 
 
    var button1 = '<a href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1 
 
    var button2 = '<a href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2 
 
    var button3 = '<a href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3 
 
    var button4 = '<a href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4 
 
    var button5 = '<a href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5 
 

 
    //Hide the default button 
 
    $('.slide-inner a').hide(); 
 

 
    //Add the new buttons. Delete the lines you don't need 
 
    $('.slide-item:nth-of-type(1) .slide-inner').append(button1); //Slide 1 
 
    $('.slide-item:nth-of-type(2) .slide-inner').append(button2); //Slide 2 
 
    $('.slide-item:nth-of-type(3) .slide-inner').append(button3); //Slide 3 
 
    $('.slide-item:nth-of-type(4) .slide-inner').append(button4); //Slide 4 
 
    $('.slide-item:nth-of-type(5) .slide-inner').append(button5); //Slide 5 
 
});

+2

的可能的複製[如何打開在HTML新標籤的鏈接?](http://stackoverflow.com/questions/17711146/how-to-open-link-in-new-tab-on- html) – Sojtin

+0

使用屬性target = _blank在標籤 –

回答

2

您需要設定目標這一點。

jQuery(function($) { 

    //Define the new buttons. Delete the lines you don't need 
    var button1 = '<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1 
    var button2 = '<a target="_blank" href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2 
    var button3 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3 
    var button4 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4 
    var button5 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5 

    //Hide the default button 
    $('.slide-inner a').hide(); 

    //Add the new buttons. Delete the lines you don't need 
    $('.slide-item:nth-of-type(1) .slide-inner').append(button1); //Slide 1 
    $('.slide-item:nth-of-type(2) .slide-inner').append(button2); //Slide 2 
    $('.slide-item:nth-of-type(3) .slide-inner').append(button3); //Slide 3 
    $('.slide-item:nth-of-type(4) .slide-inner').append(button4); //Slide 4 
    $('.slide-item:nth-of-type(5) .slide-inner').append(button5); //Slide 5 
}); 
1

使用target=_blank作爲

<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a> 
2

HTML的屬性添加target="_blank"所有鏈接元素

var button1 = '<a target="_blank" href="http://www.google.com" class="roll-button button-slider">Read More</a>'; //Slide 1 
    var button2 = '<a target="_blank" href="http://www.yahoo.com" class="roll-button button-slider">Read More</a>'; //Slide 2 
    var button3 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 3</a>'; //Slide 3 
    var button4 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 4</a>'; //Slide 4 
    var button5 = '<a target="_blank" href="http://example.org" class="roll-button button-slider">Button 5</a>'; //Slide 5 
相關問題