Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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_Dom - Fatal编程技术网

Jquery 向窗体添加文本输入

Jquery 向窗体添加文本输入,jquery,html,dom,Jquery,Html,Dom,我想向表单添加输入,但无法使其工作。加载页面时,单击“提交”并在$\u POST数组中循环,表单中未添加任何输入 <!DOCTYPE html> <html> <head> </head> <body> <script> $('#myOrder').append('<input type="text" name="test" value="product">'); </script&

我想向表单添加输入,但无法使其工作。加载页面时,单击“提交”并在$\u POST数组中循环,表单中未添加任何输入

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <script>
    $('#myOrder').append('<input type="text" name="test" value="product">');
    </script>
    <form id="myOrder" action="" method="post">
        <input type="submit" value="Submit">
    </form>
    <?php
    if ($_POST)
        {
        foreach($_POST as $key => $value)
            {
            echo $key . "<br>";
            echo $value;
            }
        }
    ?>
</body>
</html>

$('#myOrder')。附加('');

非常感谢您的帮助

尝试将代码放入
$(文档)。ready()

$(文档).ready(函数(){
$('#myOrder')。附加('');
});
嗯, 您可以尝试将输入作为这样的数组

$('#myOrder').append('<input type="text" name="input[]" value="product">');
$('#myOrder')。追加('';

GL

您将脚本称为哪里?是否包含JQuery?@Jon Mark Perry。我将append()放在外部文件的函数中,并在加载addEventListener时调用该函数。@Vucko。不知道你在说什么,谢谢你,哈米德。Shokran。对不起,我的回复太晚了,我正想咬一口。我不认为必须调用append(),因为它位于文档正文中。不客气。最好将我的代码放在
部分中。
$('#myOrder').append('<input type="text" name="input[]" value="product">');