Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用JQuery向每个表头(th)追加一些文本_Javascript_Jquery_Html Table_Append - Fatal编程技术网

Javascript 使用JQuery向每个表头(th)追加一些文本

Javascript 使用JQuery向每个表头(th)追加一些文本,javascript,jquery,html-table,append,Javascript,Jquery,Html Table,Append,我试图在每个th中添加一些。表头是根据数据库列动态生成的 以下是我所拥有的: <table id="dynamic_id" class="table table-striped table-bordered"> <thead> <tr> <th>Company Name</th> <th>Email</th> <

我试图在每个th中添加一些。表头是根据数据库列动态生成的

以下是我所拥有的:

<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事件上使用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">

您必须使用
append
jquery方法

另外,使用
find
方法获取所有
th
DOM元素

$('.table.table striped').find('thead tr th').append('');
log($('.table.table条带化').html())

公司名称
电子邮件
可移动的
地址
//尸体在这里
试试这个:

$(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">');
});
$(文档).ready(函数(){
$('table').find('th')append('');
});

欢迎使用堆栈溢出!请拿着,环顾四周,通读,特别是做你的研究,包括通读,并尝试做这项工作。如果你遇到了一个特定的问题,经过更深入的研究,如果你不能解决它,在这里的现场,张贴你的尝试,以及你遇到的问题。人们会很乐意提供帮助。使用if表动态统计列数,然后使用每个表将您想要的内容追加到该表中。您实际尝试了什么?我什么都没看到。你不需要
each()
here@RoryMcCrossan,谢谢你的观点!已更新。此处不需要
each()
。还有一点是,
id
是在运行时动态生成的,因此按它选择可能不起作用。谢谢@rorymcrossan,我已经更新了我的答案。我使用了
每个
来生成动态代码。我知道他想添加到所有<代码> <代码>,所以我们可以简单地认为它是一个选择器。我不知道这意味着什么,但是您仍然不需要<代码> EAH()>“代码>动态”或NoTI移除<代码> EAh()<代码> >。你就是那个人。谢谢:-)