Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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动态添加文本字段_Javascript_Jquery - Fatal编程技术网

使用Javascript动态添加文本字段

使用Javascript动态添加文本字段,javascript,jquery,Javascript,Jquery,我目前正在尝试使用javascript动态添加一个文本框。我有配料和数量,我希望能够在单击添加配料后继续添加 我的Javascript如下所示: $('.recipe-ingredients #addNewIngredient').on('click', function () { var i = $('.recipe-ingredients .ingredient').size() + 1; $('<div class="form-group ingred

我目前正在尝试使用javascript动态添加一个文本框。我有配料和数量,我希望能够在单击添加配料后继续添加

我的Javascript如下所示:

$('.recipe-ingredients #addNewIngredient').on('click', function () {
        var i = $('.recipe-ingredients .ingredient').size() + 1;
        $('<div class="form-group ingredient"><label class="control-label" for="searchinput">Ingredients</label><div><input id="ingredient_' + i + '" name="ingredients[]" type="text" placeholder="Ingredients" class="form-control input-md"></div></div><a href="javascript:void(0)" class="pure-button pure-u-1-6 pure-button-primary" id="addNewIngredient">Add Ingredient</a></div>').appendTo($('.recipe-ingredients .ingredients'));
        $('<div class="form-group"><label class="control-label" for="buttondropdown">Quantity</label><div class="input-group"><input id="quantity_' + i + '" name="quantity[]" class="form-control" placeholder="Quantity" type="text"><div class="input-group-btn"><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Measure<span class="caret"></span></button><ul class="dropdown pull-right"><li><a href="#">Grams</a></li><li><a href="#">Ounces</a></li><li><a href="#">Option three</a></li></ul></div></div>').appendTo($'.recipe-quantities .quantities'));
有人能告诉我我做错了什么吗

.appendTo($'.recipe quantities.quantities')


也许你的意思是
.appendTo($('.recipe quantities.quantities'))

嗨,谢谢你的回复。如果你看一下代码,我实际上已经有了双括号,所以我不认为是这样。我想卢卡斯指的是
$
后面的开始部分。您有一个
$
,后面紧跟着一个不带括号的引号
Uncaught SyntaxError: Unexpected string