Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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动态添加到现有th_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript 如何使用Jquery将th动态添加到现有th

Javascript 如何使用Jquery将th动态添加到现有th,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,如何使用Jquery动态地为th添加值。我希望在标题7之后将这些值附加到标题8和标题9 <thead> <tr> <th>Heading1</th> <th>Heading2</th> <th>Heading3</th> <th>Heading4</th> <th>Heading

如何使用Jquery动态地为th添加值。我希望在标题7之后将这些值附加到标题8和标题9

<thead>
    <tr>
        <th>Heading1</th>
        <th>Heading2</th>
        <th>Heading3</th>
        <th>Heading4</th>
        <th>Heading5</th>
        <th>Heading6</th>
        <th>Heading7</th>           
    </tr>
</thead>

标题1
标题2
头3
头4
标题5
头6
头7

使用jQuery
追加

//adds new <th> Heading8 after Heading7
$('thead tr').append( $('<th />', {text : 'Heading8'}) )

//adds new <th> Heading9 after Heading8
$('thead tr').append( $('<th />', {text : 'Heading9'}) )
//在标题7之后添加新标题8
$('thead tr').append($('',{text:'Heading8'}))
//在标题8之后添加新标题9
$('thead tr').append($('',{text:'Heading9'}))
编辑

附加到特定表:

<thead>
  <tr id="selectMe">
    <th>Heading1</th>
    <th>Heading2</th>         
  </tr>
</thead>

标题1
标题2
然后使用:

$('#selectMe').append( $('<th />', {text : 'Heading3'}) )
$('#selectMe')。追加($('',{text:'Heading3'}))

使用jQuery
追加

//adds new <th> Heading8 after Heading7
$('thead tr').append( $('<th />', {text : 'Heading8'}) )

//adds new <th> Heading9 after Heading8
$('thead tr').append( $('<th />', {text : 'Heading9'}) )
//在标题7之后添加新标题8
$('thead tr').append($('',{text:'Heading8'}))
//在标题8之后添加新标题9
$('thead tr').append($('',{text:'Heading9'}))
编辑

附加到特定表:

<thead>
  <tr id="selectMe">
    <th>Heading1</th>
    <th>Heading2</th>         
  </tr>
</thead>

标题1
标题2
然后使用:

$('#selectMe').append( $('<th />', {text : 'Heading3'}) )
$('#selectMe')。追加($('',{text:'Heading3'}))

只需将此添加到jQuery:

$(document).ready( function() {
    $('table thead th:last-child').after('<th>test</th>');
});
$(文档).ready(函数(){
$('table thead th:last child')。在('test')之后;
});

只需将此添加到jQuery:

$(document).ready( function() {
    $('table thead th:last-child').after('<th>test</th>');
});
$(文档).ready(函数(){
$('table thead th:last child')。在('test')之后;
});

使用以下命令:

$('#tableId')。追加($('',{text:'您的文本'}))

使用以下命令:

$('#tableId')。追加($('',{text:'您的文本'}))

$('thead tr').append($('',{text:'Heading8'}))
如果一个页面中有许多表,并且如果我必须只将这些表附加到一个特定的表中,那么我如何才能达到我的要求。给该表一个ID
$('thead tr')。append($('',{text:'Heading8'}))
如果一个页面中有许多表,如果我必须只将其附加到一个特定的表中,那么我如何才能达到我的要求。给该表一个IDI如果一个页面中有许多表,如果我必须只将其附加到一个特定的表中,那么我如何才能达到我的要求。给每个特定的表一个
id
,然后根据其
id
选择带有jQuery的表。然后像以前一样使用
append
。如果一个页面中有许多表,并且如果我必须只将这些表附加到一个特定的表,那么我如何才能达到我的要求。为每个特定的表指定一个
id
,然后根据其
id
选择带有jQuery的表。然后像以前一样使用
append
。谢谢,你的代码帮助我实现了要求谢谢,你的代码帮助我实现了要求