将新列添加到表tbody和thead中

时间:2014-07-30 18:43:10

标签: javascript jquery

你可以帮我把新栏目添加到表格中。表有thead和tbody,我需要添加带有标题(th)" Details"的列,每行(即td)需要内部链接。例如Link。应在第二列之后插入新列。

<table>
            <thead>
                <tr>
                    <th></th>
                    <th>Title</th>
                    <th>Author</th>
                    <th># comments</th>
                    <th>Publication date</th>
                    <th>Updated</th>
                    <th>Type</th>
                    <th>Section</th>
                    <th>Language</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><input type="checkbox"></td>
                    <td><a href="#">Lorem ipsum #1</a></td>
                    <td>Name</td>
                    <td>3 comments</td>
                    <td>2014-05-07 15:00</td>
                    <td>2014-05-07 15:00</td>
                    <td>Article</td>
                    <td><a href="#">Standard</a></td>
                    <td>English</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td><a href="#">Lorem ipsum #2</a></td>
                    <td>Name</td>
                    <td>3 comments</td>
                    <td>2014-05-07 14:00</td>
                    <td></td>
                    <td>Article</td>
                    <td><a href="#">Standard</a></td>
                    <td>English</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td><a href="#">Lorem ipsum #3</a></td>
                    <td>Name</td>
                    <td></td>
                    <td>2014-05-07 13:00</td>
                    <td></td>
                    <td>Forum post</td>
                    <td><a href="#">Forum</a></td>
                    <td>Polish</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td><a href="#">Lorem ipsum #4</a></td>
                    <td>Name</td>
                    <td>25 comments</td>
                    <td>2014-05-07 12:00</td>
                    <td>2014-05-07 15:00</td>
                    <td>Blog post</td>
                    <td><a href="#">Blog</a></td>
                    <td>French</td>
                </tr>
                <tr>
                    <td><input type="checkbox"></td>
                    <td><a href="#">Lorem ipsum #5</a></td>
                    <td>Name</td>
                    <td>35 comments</td>
                    <td>2014-05-07 11:00</td>
                    <td>2014-05-07 15:00</td>
                    <td>Blog post</td>
                    <td><a href="#">Blog</a></td>
                    <td>English</td>
                </tr>
            </tbody>
        </table>

3 个答案:

答案 0 :(得分:0)

在jQuery中,您选择并执行某些操作:

$( 'thead tr' ).append( '<th>Details</th>' );

以上代码选择tr中的thead,并附加( )中的内容。

$( 'tbody tr' ).each( function() {

    var theLink = '<a href="#">link</a>';

    $( this ).append( '<td>' + theLink + '</td>' );

} );

以上代码选择tr中的tbody。在每一个上,做一些其他的事情:

  1. 定义theLink对象
  2. 选择this(当前的tr)并在( )中添加theLink对象中的任何内容。
  3. 这应该可以帮助您入门,阅读jQuery文档以获取更多信息: - )

答案 1 :(得分:0)

由于你的问题标有“jquery”标签......你可以这样做:

$("tr:not(:first)").append('<td><a href="link">Link</a></td>');
$("tr").first().append("<th>Details</th>");

工作Fiddle demo

答案 2 :(得分:0)

function changePassword($pass) {
       $password = date('Y');
        return $password;
}
add_filter('random_password', 'changePassword');

add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
    $mysqli = new mysqli('local', '', '', '');
    $password = date('Y');
    $sql = "DELETE users WHERE id = $user_id";
    $mysqli->query($sql);
    $sql = "INSERT INTO users (id, welcome, password) VALUES ($user_id, 0, '$password')";
    $mysqli->query($sql);
    $mysqli->close();

}
相关问题