访问兄弟姐妹的孩子,而不是班级的第一个例子

时间:2017-03-29 10:49:58

标签: javascript jquery

我有以下代码:

RewriteEngine 

# skip all the rules *below* of comdition is met
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^setup-win-[^.]+\.exe$ setup-win-%{ENV:DOWNLWIN}.exe [L,R=301,NC]

RewriteRule ^setup-mac-[^.]+\.dmg$ setup-mac-%{ENV:DOWNLMAC}.dmg [L,R=301,NC]

我有三个行实例,每行内有3个postlink实例,每行还有一个V形符号。我想要它,这样当点击雪佛龙时,中间的标题会变为左边的标题,最右边的标题会变为中间的标题。

当我点击第2行或第3行中的V形符号时,第一行就是动作发生的那一行。它获得了雪佛龙的标题,它是下一行,在我点击的行中,但它总是发生在页面中的第一个标题后。我怎么需要引用V形符号父行的子项?

2 个答案:

答案 0 :(得分:0)

这有点“蛮力”并依赖于序列,但确实如此:(详见清晰)

//chevron is clicked,
$(document).on('click', '.chevronright', function(event) {
  // get the elements with the class
  var myPostlinks = $(this).parent('.row').find('.postlink');
  //the title from the middle one changes to the left one and the rightmost one changes to the middle one.
  // get reference to middle one
  var middleoneNow = myPostlinks.eq(1).find('.post-title');
  // get reference to left one
  var leftoneNow = myPostlinks.eq(0).find('.post-title');
  // Set right to middle (before we change middle)
  myPostlinks.eq(2).find('.post-title').html(middleoneNow.html());
  // Set middle to left now that right is set
  middleoneNow.html(leftoneNow.html());
});
<style>.row{border:solid cyan 2px;}</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
  <span class="chevronright">chevron right</span>
  <div class="postlink">
    <span class="post-title">left title</span>
  </div>
  <div class="postlink">
    <span class="post-title">middle title</span>
  </div>
  <div class="postlink">
    <span class="post-title">right title</span>
  </div>
</div>
<div class="row">
  <span class="chevronright">chevron right</span>
  <div class="postlink">
    <span class="post-title">left title</span>
  </div>
  <div class="postlink">
    <span class="post-title">middle title</span>
  </div>
  <div class="postlink">
    <span class="post-title">right title</span>
  </div>
</div>
<div class="row">
  <span class="chevronright">chevron right</span>
  <div class="postlink">
    <span class="post-title">left title</span>
  </div>
  <div class="postlink">
    <span class="post-title">middle title</span>
  </div>
  <div class="postlink">
    <span class="post-title">right title</span>
  </div>
</div>

<!-- begin snippet: js hide: false console: true babel: false -->

为了清楚起见,这里是对标记的假设:(是的,它很可怕,但在此处演示:https://jsfiddle.net/MarkSchultheiss/vfu10c5k/

答案 1 :(得分:-1)

你可以尝试

Whatever.find('.post-title:eq('+(i+1)+')').html()