Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
Jquery 如何在HTML5表中的当前行下方创建空行?_Jquery_Html - Fatal编程技术网

Jquery 如何在HTML5表中的当前行下方创建空行?

Jquery 如何在HTML5表中的当前行下方创建空行?,jquery,html,Jquery,Html,我试图创建一个可编辑的表格,在填充一行后,点击tab按钮后,当前行下方会呈现一个空行。加载表时,最初应显示一个空行。请有人帮我达到我的要求 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Dynamic table</title> <link rel="stylesheet" href="https://maxcdn.boo

我试图创建一个可编辑的表格,在填充一行后,点击tab按钮后,当前行下方会呈现一个空行。加载表时,最初应显示一个空行。请有人帮我达到我的要求

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Dynamic table</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js">        </script>
</head>
<body>
    <table class="table">
        <thead>
            <tr>
                <th>#</th>
                <th>user/site</th>
                <th>channel name</th>
                <th>actions</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td contentEditable="true">1</td>
                <td contentEditable="true">www.google.com</td>
                <td contentEditable="true">channel-1</td>
                <td contentEditable="true">delete</td>
            </tr>
            <tr>
                <td contentEditable="true">2</td>
                <td contentEditable="true">www.google.com</td>
                <td contentEditable="true">channel-1</td>
                <td contentEditable="true">delete</td>
            </tr>
            <!-- and so on -->
        </tbody>
    </table>
</body>
</html>

动态表
#
用户/站点
频道名称
行动
1.
www.google.com
第一频道
删除
2.
www.google.com
第一频道
删除

使用:last选择器在tbody中查找最后一个tr,然后像这样附加html

$('tbody >tr:last').after('<tr><td contenteditable="true">4</td><td contenteditable="true">a</td><td contenteditable="true">a</td><td contenteditable="true">a</td></tr>');
$('tbody>tr:last')。在('4aaa')之后;

只需在
ready
-处理程序中定义javascript,即可在页面加载时添加新行。 要在最后一次
td
中每次点击
选项卡
时添加新行,您有权按
选项卡键
(键代码9,请参阅以获取完整参考)。在动态添加元素时,必须使用

$(文档).ready(函数(){
$('.table-tbody')。追加('');
$('.table').on('keydown','td:last child',函数(e){
var keyCode=e.keyCode | | e.which;
if(keyCode==9){
$('tbody')。附加('');
}
});
});

参考


你的javascript代码在哪里?一个简单的谷歌搜索会产生几十个结果。StackOverflow是一个可以在搜索后提问的地方。
$(document).ready(function(){    
    $('.table tbody').append('<tr><td contenteditable="true"></td><td contenteditable="true"></td><td contenteditable="true"></td><td contenteditable="true"></td></tr>');

    $('.table').on('keydown', 'td:last-child', function (e) {
        var keyCode = e.keyCode || e.which;

        if (keyCode == 9) {
            $('tbody').append('<tr><td contenteditable="true"></td><td contenteditable="true"></td><td contenteditable="true"></td><td contenteditable="true"></td></tr>');
        }
    });
});