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

时间:2018-11-05 22:01:24

标签: javascript jquery sharepoint sharepoint-2010

我有一个SharePoint表,并希望使用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之间动态插入它

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>’);
};

我正在尝试通过在它们之间添加动态链接2作为链接1和链接3之间的锚点,或者通过addRow函数替换它(如果已存在)。 我的问题是我可以用 groupstring 插入 tbody 后的 tbody ,但是我想插入 tbody 一个空白的 tbody 之后。 有人可以帮忙修改:

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

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

$(‘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()

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

1 个答案:

答案 0 :(得分:0)

$('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属性。

相关问题