用于在新标签

时间:2017-02-28 07:32:25

标签: javascript jquery html wordpress

我想编辑Sydney主题(wordpress)的滑块按钮,为每个按钮分别添加链接,我找到了以下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
});

4 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

target="_blank"就是您所需要的:

   //Define the new buttons. Delete the lines you don't need
   var button1 = '<a href="http://www.google.com" target="_blank" class="roll-button button-slider">Read More</a>'; //Slide 1

等。

了解更多信息 - 请看这里: https://developer.mozilla.org/en/docs/Web/HTML/Element/a#Attributes

答案 2 :(得分: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
});

答案 3 :(得分:1)

使用html的target=_blank属性

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