2016-12-27 21 views
0

任何人都有一个想法如何在bootstrap-table头部的左边添加内容?就像下面的图片一样,我想添加一个图标(问号或其他)作为可点击的链接。bootstrap-table:th - 在左边添加一个图标

enter image description here

jsFIDDLE

<table id="summaryTable"> 
    <thead> 
     <tr> 
      <th data-field="id" data-align="center" data-width="20px" >id</th> 
      <th data-field="name" data-align="center" data-sortable="true">Name</th> 
      <th data-field="type" data-align="center" data-sortable="true">type</th> 
     </tr> 
    </thead> 
</table> 
+0

你检查的答案吗? – Dekel

+0

是的,我仍在检查是否足以处理我需要的代码,如果我没有更多问题回答您的问题。这似乎是我需要的答案。 – soonic

回答

1

您可以将元素添加到每个th

$('#summaryTable thead th').each(function() { 
    s = $('<span style="position: absolute; left: 4px; top: 8px; cursor: pointer;">?</span>') 
    s.click(function(e) { 
     e.stopPropagation(); 
     alert('Question mark clicked') 
    }); 
    $(this).append(s) 
    }) 

注意e.stopPropagation();以确保问号的点击次数不会造成也点击整个TH

这是你的jsfiddle的叉:
https://jsfiddle.net/dekelb/e403uvuh/

+0

我发现'position:relative;'[jsFiddle](https://jsfiddle.net/e403uvuh/1/)的副作用。如果我添加它,那么标题的单元格边框消失了。问号也与文本不在同一行。你知道如何解决它吗? – soonic

+0

只需设置正确的“顶部”值。我把它设置为'12px',在你的例子中,你可能会想'4px' – Dekel

+0

看看我的第一条评论中更新的jsFiddle链接。我需要不同的'顶部'为不同的标题单元格。我修改了我的例子,因为你的代码(这非常接近我需要的)给了我不好的副作用。 – soonic