Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.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 每次在上一个文本字段中按下一个键时,都无法添加文本字段_Jquery_Html - Fatal编程技术网

Jquery 每次在上一个文本字段中按下一个键时,都无法添加文本字段

Jquery 每次在上一个文本字段中按下一个键时,都无法添加文本字段,jquery,html,Jquery,Html,我刚刚开始,但我真的很喜欢使用jquery,在这里很容易找到关于其他问题的答案,但现在我坚持使用这个问题。我目前将其设置为alert:pressed,但我尝试使用append在按下某个键时添加文本字段,但一直出现错误 当用户输入密钥时,它应该在原始texfield下添加一个新的texfield 提前谢谢 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script&

我刚刚开始,但我真的很喜欢使用jquery,在这里很容易找到关于其他问题的答案,但现在我坚持使用这个问题。我目前将其设置为alert:pressed,但我尝试使用append在按下某个键时添加文本字段,但一直出现错误

当用户输入密钥时,它应该在原始texfield下添加一个新的texfield

提前谢谢

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>



    <input type="text" name="keydown" id="keypress" />




    <script>

        $(document).ready(function () {

            $("#keypress").keydown(function () {

                alert("pressed");


        });

    });

    </script>

$(文档).ready(函数(){
$(“#按键”).keydown(函数(){
警惕(“按下”);
});
});

将类添加到当前文本框中,然后使用事件委派:

<input type="text" name="keydown" id="keypress" class="textboxpress" />

$(document).ready(function () {
    $(document).on('keydown', '.textboxpress', function () {
        $(this).after("<input type='text' class='textboxpress' />");
    });
});

$(文档).ready(函数(){
$(文档).on('keydown','textboxpress',函数(){
$(此)。在(“”)之后;
});
});
这将在焦点框之后添加一个新的文本框。如果您有要附加到的特定容器,请使用容器选择器替换
$(this)
,并将
之后的
替换为
附加


请发布您试图使用的代码,这些代码会给您带来错误。这很快,谢谢tymeJV。有没有办法让新的textfield运行相同的函数?请查看PXL的答案,最好是:D。简而言之,您需要使用事件委派。@user2506767--我也更新了这个答案--它满足了您的需要。谢谢,非常感谢您的帮助