将tbody置于当前tbody下方的旁边

将tbody置于当前tbody下方的旁边

本文介绍了将tbody置于当前tbody下方的旁边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SharePoint表,并希望使用groupstring在表体的右下角获取表的表体.

I have a SharePoint table and would like to get the tbody of the table right one below the tbody with groupstring.

样品表

<tbody groupstring="%3B%23Application%3B%23">
<tr><td> : Application </td></tr></tbody>
<tbody></tbody>
<tbody>
<tr><td><a href="https://link1.com">Link 1</a></td></tr>
<tr><td><a href="https://link3.com">Link 3</a></td></tr>
</tbody>

我将从Json获得另一个链接Link2,并使用Jquery在Link1和Link3之间动态插入它

I will be getting another link Link2 from Json and dynamically inserting it between Link1 and Link3 with Jquery

var addRow=function(url,displayName){
Var counter=0;
$(‘tbody[groupstring="%3B%23Application%3B%23"]’).closest(‘tbody’).find(‘td’).each(function(){
counter++;
If($(this).find(‘td:eq(0)’).text() > displayName){
$(this).before(makeRow(url,displayName));
} else {
If($(this).find(‘td:eq(0)’).text() === displayName){
$(this).html(makeRow(url,displayName));
Return false;
}}
If($(this).closest(‘table’).find(‘td.md-vb2’).length === counter){
$(this).parent().after(makeRow(url,displayName));
}
});
};

Var makeRow = function(url,displayName){
return (‘<tr><td><a href="‘ + url + ‘">’+displayName+’</a></td></tr>’);
};

我正在尝试在Link1&之间添加动态Link2.通过将Link3作为锚点放置在它们之间,或者如果addRow函数已经存在,则将其替换.我的问题是我可以用 groupstring 插入 tbody 后的 tbody ,但是我想插入 tbody 一个空白的 tbody 之后.有人可以帮忙修改:

I am trying to add the dynamic Link2 between Link1 & Link3 as anchor by placing in between or replace if already exists by addRow function.My problem is that I can insert in the tbody after the tbody with groupstring but I want to insert in tbody one after the blank tbody.Can somebody help modify:

 $(‘tbody[groupstring="%3B%23Application%3B%23"]’).closest(‘tbody’).find(‘td’).each(function(){

要在空白的 tbody 之后访问/获取tbody *?我什至尝试过:

To access/get the tbody* one after the blank tbody?I even tried:

$(‘tbody[groupstring="%3B%23Application%3B%23"]’).closest(‘tbody’).next(‘tbody’).find(‘td’).each(function(){

还有

$(‘tbody[groupstring="%3B%23Application%3B%23"]’).closest(‘tbody’).closest(‘tbody’).find(‘td’).each(function()

但是它没有用.非常感谢您的帮助.

But it did not work.Any help is much appreciated.

推荐答案

$('tbody[groupstring]').nextAll('tbody:eq(1)')应该这样做.

演示:

$(function() {
  var $target = $('tbody[groupstring]').nextAll('tbody:eq(1)');
  console.log($target.html());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table>
  <tbody groupstring="%3B%23Application%3B%23">
    <tr>
      <td>Application</td>
    </tr>
  </tbody>
  <tbody></tbody>
  <tbody>
    <tr>
      <td><a href="https://link1.com">Link 1</a></td>
    </tr>
    <tr>
      <td><a href="https://link3.com">Link 3</a></td>
    </tr>
  </tbody>
</table>

还请注意,groupstring不是有效的HTML属性.

Also note that groupstring is not a valid HTML attribute.

这篇关于将tbody置于当前tbody下方的旁边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:46