我想在每个内部添加一些附加内容。表头是动态生成的,取决于数据库列
以下是我所拥有的:
<table id="dynamic_id" class="table table-striped table-bordered">
<thead>
<tr>
<th>Company Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Address</th>
</tr>
</thead>
<tbody>
//body goes here
</tbody>
</tbody>
</table>
什么是期望在Ready Event上使用jQuery。
<th>Company Name
<span class="js-sorter-desc fa fa-chevron-down pull-right"></span>
<span class="js-sorter-asc fa fa-chevron-up pull-right"></span>
</th>
这应该适用于每一个......
<span class="js-sorter-desc fa fa-chevron-down pull-right"></span>
<span class="js-sorter-asc fa fa-chevron-up pull-right">
答案 0 :(得分:1)
您必须使用append
jquery 方法。
另外,使用find
方法获取所有th
DOM 元素。
$('.table.table-striped').find('thead tr th').append('<span class="js-sorter-desc fa fa-chevron-down pull-right"></span><span class="js-sorter-asc fa fa-chevron-up pull-right"></span>');
console.log($('.table.table-striped').html());
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="dynamic_id" class="table table-striped table-bordered">
<thead>
<tr>
<th>Company Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Address</th>
</tr>
</thead>
<tbody>
//body goes here
</tbody>
</table>
&#13;
答案 1 :(得分:0)
试试这个:
$(document).ready(function(){
$('table').find('th')append('<span class="js-sorter-desc fa fa-chevron-down pull-right"></span><span class="js-sorter-asc fa fa-chevron-up pull-right">');
});